I need to pass a shell variable to awk in gnuplot but I get error messages : The variable is set in the sript and is called FILE. This changes according to date. My code : (in a Gnuplot script)
plot FILE using 1:14 with points pointtype 7 pointsize 1 # this works fine
replot '< awk ''{y1 = y2; y2 = $14; if (NR > 1 && y2 - y1 >= 100) printf("\n") ; if (NR > 1 && y2 -y1 <= -100) printf("\n"); print}'' FILE' using 1:14 with linespoints
Err msg
awk: fatal: cannot open file `FILE' for reading (No such file or directory)
When I hard code the FILE path the replot works.
Could anyone clarify the code I need to pass this variable to awk? Am I on the right track with something like :
% environment_variable=FILE
% awk -vawk_variable="${environment_variable}" 'BEGIN { print awk_variable }' ?
Here is my Gnuplot script code: cobbled together from other posts mostly..
#FILE selection - we want to plot the most recent data file
FILE = strftime('/data/%Y-%m-%d.txt', time(0)) # this is correct
print "FILE is : " .FILE
#set file path variable for awk : (This is where my problem is)
awk -v var="$FILE" '{print var}'
awk '{print $0}' <<< "$FILE"
Thank you in advance
"$FILE"instead ofFILE. in your second, on the last line you don't need<<<.awk -v var="$FILE" '{print var}'is incomplete syntax and will hang your computer as it needs a file as argument. Just useawk '{print $0}' "$FILE"<<<, its get the data from a variable intoawkwith this.FILEjust stored the path of the file, not its entire content. If that's the case then you are right indeed. EDIT: after further reading, it seems OP just stored the path of the most recent file in$FILE. He should then remove the<<<(otherwise his awk command will just print the path)