Hi all

Please help me out.

I plot a file output1.txt in the following way ::

gnuplot> plot "output1.txt" using 1:2 with lines, \
plot "output1.txt" using 1:3 with lines

BUT now I have many data files,

output1.txt, output2.txt, output3.txt, ....,....... ,output1000.txt

I need to plot each one of them in gnuplot, and save them respectively in

graph1.jpeg, graph2.jpeg, graph3.jpeg, ............, graph1000.jpeg

It is very cumbersome if I plot and save 1 file at a time.

Is there an easy way, using loops in a Shell script that can PLOT and SAVE them

Please kindly help

I'm assuming that all of plots are identical.

First you need to set up a template file containg the command for gnuplot like this.

# template.gnuplot
set term png
set output "OUTFILE"
plot "DATAFILE" using 1:2 with lines \
     "DATAFILE" using 1:3 with lines

Now you can plot the datafiles. This script will loop from 1 to 10, modifying the gnuplot command file on each iteration.

# Plotting.sh

touch $tmpfile

while [ $x -le 10 ]
  sed '
        s/OUTFILE/graph'${x}'.png/' template.gnuplot # > $tmpfile
  gnuplot $tmpfile
  x=$((x + 1))
rm /tmp/temp.$$

Thanks dear shibblez.
Your code was helpful.

I have also figured out an another way as told to me by a friend. It is

i = 1
n = 1000
set terminal jpeg
load "loop.plt"

"loop.plt" contains:

filename = "output".i.".txt"
plotfile = "graph".i.".jpg"
print filename." ".plotfile

set output plotfile
plot filename using 1:2, "" using 1:3
set output


if (i <= n) reread


This article has been dead for over six months. Start a new discussion instead.