Anthony T.
Anthony T.

Reputation: 11

Pre-process a gnuplot script with bash

I have a gnuplot script file which contains comments, indents and empty lines, like

plot_residuals.gnu

set term pngcairo notransparent enhanced size 640,420 crop 
    # size defaut = 640,480
    # font "Times-New-Roman,20pt"
set output "plot_residuals.png"
  
set logscale y ; set format y "10^{%L}"
set ylabel 'Residuals'
set xlabel 'Iteration'
# set key out
# set yrange [:10]

plot \
'Ux' w l ti 'Ux' ,\
'Uy' w l ti 'Uy' ,\
'Uz' w l ti 'Uz' ,\
'p' w lp pn 20 dt 4 ti 'p' ,\

'e' u 1:2 w lp pn 20 ti 'e' ,\
# 'h' u 1:2 w lp pn 20 ti 'h' ,\
# 'i' u 1:2 w lp pn 20 ti 'i' ,\

'k' w l dt 2 ti 'k' ,\
# 'epsilon' w l dt 2 ti 'eps' ,\
'omega' w l dt 2 ti 'omg' ,\

I was wondering if it is possible to pre-process this file (by removing comments, indents and empty lines without editing the original file) before passing it into gnuplot with only one command line. I tried somethings like

gnuplot < cat plot_residuals.gnu | sed -e "s/^[[:space:]]*//g" -e "/^$/d" -e "/^\#/d"
gnuplot $(sed -e "s/^[[:space:]]*//g" -e "/^$/d" -e "/^\#/d" plot_residuals.gnu)
gnuplot -pe < "$(sed -e "s/^[[:space:]]*//g" -e "/^$/d" -e "/^\#/d" plot_residuals.gnu)"

without success. But, of course it works with a temporary file by executing

sed -e "s/^[[:space:]]*//g" -e "/^$/d" -e "/^\#/d" plot_residuals.gnu > tmp.gnu  
gnuplot -pe tmp.gnu

Thanks for your help

Upvotes: 0

Views: 54

Answers (1)

Anthony T.
Anthony T.

Reputation: 11

I knew I was close. This works ! :-)

gnuplot -pe "< sed -e "s/^[[:space:]]*//g" -e "/^$/d" -e "/^\#/d" plot_residuals.gnu"

gnuplot -pe <( sed -e "s/^[[:space:]]*//g" -e "/^$/d" -e "/^\#/d" plot_residuals.gnu )

sed -e "s/^[[:space:]]*//g" -e "/^$/d" -e "/^\#/d" plot_residuals.gnu | gnuplot -pe 

Upvotes: 1

Related Questions