1
votes

This command works well in a GNUplot script to find the line in a file with the value -1.98

system("/usr/bin/awk '/-1.98/{print $2 $1}' /path/to/myfile.txt")  

Given the GNUplot variable STATS_min_y resulting from a plot command, how would I pass STATS_min_y into that system() call in place of the -1.98 value?

system("/usr/bin/awk '/STATS_min_y/{print $2 $1}' /path/to/myfile.txt")  

and similar variants fail with a demand for a missing parenthesis.

1
You probably want something like system("/usr/bin/awk -v value=-1.98 '$0 ~ value {print $2 $1}' /path/to/myfile.txt") - fedorqui 'SO stop harming'
Using whatever string concatenation support GNUplot has to construct that command string. - Etan Reisner
The concat operator for GNUplot is the period, and this works system("/usr/bin/awk -v value= ". lowValue . " '$0 ~ value {print $2 $1}' /path/to/myfile.txt") in the sense that it recognizes the value of the variable (lowValue) but fails with this error: unknown option -1.98 ignored, and returns every line of the file. - Dan
There must be no space after value=. - Christoph
Not sure if my guess is right: Gnuplot: how to plot max and /or min value - Christoph

1 Answers

0
votes

You can pass the result from sprintf directly to system. For example:

a = system( sprintf("awk '/%g/{print $2,$1}' myfile.txt", STATS_min_y) )