2

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?

0

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.