Max
Max

Reputation: 27

Manipulate awk arguments in gnuplot

I use awk and it's output inside gnuplot to plot data from a file. This works as follows in gnuplot:

s=`awk '{N+=$2}; END {print N}' modes/10.dat`

In gnuplot I can then work with s. However I would like to pass the argument to awk from the gnuplot code, like:

i=10
file='modes/'.i.'.dat'
s=`awk '{N+=$2}; END {print N}' file`

Unfortunately this doesn't work. I also tried sth. like:

i=10
file='modes/'.i.'.dat'    
cmd = sprintf("awk '{N+=$2}; END {print N}' %s", file)
s=`cmd`

Does anybody have an idea?

Upvotes: 2

Views: 140

Answers (1)

Christoph
Christoph

Reputation: 48420

Use

s = system(cmd)

to evaluate the shell expression contained in the gnuplot variable cmd:

i = 10
file = 'modes/'.i.'.dat'    
cmd = sprintf("awk '{N+=$2}; END {print N}' %s", file)
s = system(cmd)

Upvotes: 1

Related Questions