0

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

2
  • Have you tried a complete process substitution? something like gnuplot < <(sed ...) Commented Mar 25, 2021 at 13:39
  • 1
    Why on earth would you need to do this? Commented Mar 25, 2021 at 18:01

1 Answer 1

1

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

1 Comment

If it works for you then please accept your own answer to indicate that the problem is solved. But like Ethan commented... why do you think you have to do this?

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.