my logfile is as:
********************************************************************
maximum disp: 3.2580e-05, at node: 3, of total: 6
maximum disp: 4.2876e-05, at node: 6, of total: 6
********************************************************************
and I want to grep the number '6' dynamically and set it to maximum yrange, like:
myVar = "cat fileName | grep -m 1 'of total:' | cut -d' ' -f9"
set yrange[1:myVar]
but 'myVar' can not set to be 6
can anyone help?
Id tried some expressions without double quats like
myVar = cat fileName | grep -m 1 'of total:' | cut -d' ' -f9
and got errors
undefined variable: cat
CodePudding user response:
gnuplot> help backquotes
Command-line substitution is specified by a system command enclosed in
backquotes. This command is spawned and the output it produces replaces
the backquoted text on the command line. Exit status of the system command
is returned in variables GPVAL_SYSTEM_ERRNO and GPVAL_SYSTEM_ERRMSG.
Note: Internal carriage-return ('\r') and newline ('\n') characters are not
stripped from the substituted string. This is a change from version 5.2.
Command-line substitution can be used anywhere on the `gnuplot` command
line except inside strings delimited by single quotes.
Example:
This will run the program `leastsq` and replace `leastsq` (including
backquotes) on the command line with its output:
f(x) = `leastsq`
These will generate labels with the current time and userid:
set label "generated on `date %Y-%m-%d` by `whoami`" at 1,1
set timestamp "generated on %Y-%m-%d by `whoami`"
CodePudding user response:
I would do the following: gnuplot-only, independent from system calls and hence platform-independent.
Script:
### extract value from file into variable
reset session
$Data <<EOD
********************************************************************
maximum disp: 3.2580e-05, at node: 3, of total: 6
maximum disp: 4.2876e-05, at node: 6, of total: 6
********************************************************************
1 1.2
2 2.3
3 3.4
4 4.5
5 5.6
EOD
stats $Data u (myVar = $9) every ::1::1 nooutput
print myVar
set yrange[0:myVar]
set label 1 at graph 0.1, 0.9 sprintf("Extracted value: %g",myVar)
plot $Data u 1:2 w lp pt 7
### end of script
Result: