0

What I want:

echo {0..2} | gnuplot --persist -e "f='{OUTPUT FROM ECHO}'" myplot.plg 
0 1 2

FILE myplot.plg:

print f
#plot for [fi in f] fi.".dat" using 1 w l title sprintf(fi)

USE:

echo "python sim.py > "{0..2}".dat &" | bash -
echo "node sim.js > "{0..2}".dat &" | bash -
echo {0..2} | gnuplot --persist -e {Stack Overflow Magic?} myplot.plg

The goal would be to run many instances of this sim simultaneously (different initial conditions) using echo to create the command, & to fork the process, and bash to run it. Once the simulation is complete, I want to display all of the plots in one figure. Ex: plot {0..100}.dat nolegend

randompast
  • 697
  • 7
  • 12
  • 1
    I don't think there's really a sane way to do that. Last time I tried (many years ago) I think I ended up creating a here document for each run, and passing that as the script to Gnuplot, IIRC. – tripleee Mar 03 '17 at 07:24
  • 1
    If you have Python anyway, Matplotlib is a lot more versatile if you just need basic plotting. – tripleee Mar 03 '17 at 07:25
  • 1
    @tripleee: Have not used gnuplot before, but running a command substitution syntax inside one of the flags, `f` won't work here? – Inian Mar 03 '17 at 07:27
  • It's not specific to python, that's just an example use case. I managed to make it work with xargs and I am satisfied with the elegance. – randompast Mar 03 '17 at 07:28

1 Answers1

1

Just when I thought all hope was lost, xargs to the rescue!

echo {0..2} | xargs -I{} gnuplot --persist -e "f='{}'" myplot.plg

More fun:

alias sgp="xargs -I{} gnuplot --persist -e \"f='{}'\""
echo {0..2} | sgp plot_files.plg 

Credit to this youtube video

Edit: Doesn't work in tcsh (alias sgp command). xargs is also different.

randompast
  • 697
  • 7
  • 12