Understanding how gnuplot uses awk scripts

I have a data file

data.txt

1 1
2 2
3 3
5 4
7 5

and I'm trying to understand how gnuplot uses awk. I can build it with plot "<awk '{print $1,$2}' data.txt". However, when I try load '<./script.sh data.txt', this does not work.

script.sh

#!/bin/bash
awk 'BEGIN {
         printf "plot ";
    }
    {
        printf "%i %i\n",$1,$2
    }

' $1

Using the method script.shreturns an error:

gnuplot> plot 1 1

              ^

"<./ script.sh data.txt", line 1: unexpected or unrecognized token

It seems to me that my awk script is the functional equivalent of the inline awk operator. Why script.shdoes the method not work?

FYI, I know that I can just do plot "data.txt" u 1:2to build my data. This is just an idealized version of the more complex problem I'm trying to solve.

+4
2

awk, gnuplots plot load.

gnuplot , :

plot "<awk '{print $1,$2}' data.txt"

, popen- , , plot x, y.

script - , load , ( , , x y), ( 2 2 .

gnuplot - , ;-) - , , gnuplot.

:

gnuplot> help load
 The `load` command executes each line of the specified input file as if it
 had been typed in interactively.  Files created by the `save` command can
 later be `load`ed.  Any text file containing valid commands can be created
 and then executed by the `load` command.  Files being `load`ed may themselves
 contain `load` or `call` commands.  See `comments` for information about
 comments in commands.  To `load` with arguments, see `call`.

 Syntax:
       load "<input-file>"

 The name of the input file must be enclosed in quotes.

 The special filename "-" may be used to `load` commands from standard input.
 This allows a `gnuplot` command file to accept some commands from standard
 input.  Please see help for `batch/interactive` for more details.

 On some systems which support a popen function (Unix), the load file can be
 read from a pipe by starting the file name with a '<'.

 Examples:
       load 'work.gnu'
       load "func.dat"
       load "< loadfile_generator.sh"

 The `load` command is performed implicitly on any file names given as
 arguments to `gnuplot`.  These are loaded in the order specified, and
 then `gnuplot` exits.

gnuplot .

+2

script awk, plot. plot-command '-', .

awk script :

#!/bin/bash
awk 'BEGIN {
         printf "plot '\''-'\''\n";
    }
    {
        printf "%i %i\n",$1,$2
    }
END {
        printf "e"
    }
' $1

, . awk printf

0

All Articles