gnuplot
can handle as many files as you like in a single command.
Simply issue your plot
command separating each file and column specification with a comma (as you have begun doing above)
plot \
"folder1/data" using 1:2,
"folder1/data" using 1:3,
"folder2/data" using 1:2,
"folder2/data" using 1:3,
"folder3/data" using 1:2,
"folder3/data" using 1:3
Generally each plot
command will produce output in a separate window (it depends on how gnuplot
is called -- whether in a separate process or not).
When called from a shell script, you can spawn separate subshells to produce output in separate windows, or within a C-program, you can fork
separate processes for the same purpose.
You can also use multiplot
, see Multiplot – placing graphs next to each other « Gnuplotting
You may also find parts of you question answered here gnuplot : plotting data from multiple input files in a single graph
edit Based on Comment
OK, now that I understand you want to automate building a plot file from a list of directories named folderXX
(where XX
can be anything) below the current directory, and in each folder there will be a file named data
where you want to plot the first against each of the 2nd and 3rd columns, then you can build a temporary plot file (say tmp.plt
) by looping over the list of folderXX
(you can adjust the globbing to your needs) and outputting the plot commands as you go using simple redirection.
For example, something like the following:
#!/bin/bash
## truncate tmp.plt and set line style
echo -e "set style data lines\nplot \\" > tmp.plt
cnt=0 ## flag for adding ',' line ending
## loop over each file
for i in folder*/data; do
if ((cnt == 0)); then ## check flag (skips first iteration)
cnt=1 ## set flag to write ending comma
else
printf ",\n" >> tmp.plt ## write comma
fi
printf "\"$i\" using 1:2,\n" >> tmp.plt ## write using 1:2
printf "\"$i\" using 1:3" >> tmp.plt ## write using 1:3 (no ending)
done
echo "" >> tmp.plt ## write final newline
(note: echo
and printf
are alternated to get the desired escape behavior for the line-continuations)
When run within a directory containing folder1, folder2, folder3, folder4
, each containing a data
file, e.g.
$ tree
.
├── folder1
│ └── data
├── folder2
│ └── data
├── folder3
│ └── data
├── folder4
│ └── data
it will result in a tmp.plt
plotfile that can then be called with gnuplot -p tmp.plt
, e.g.
$ cat tmp.plt
set style data lines
plot \
"folder1/data" using 1:2,
"folder1/data" using 1:3,
"folder2/data" using 1:2,
"folder2/data" using 1:3,
"folder3/data" using 1:2,
"folder3/data" using 1:3,
"folder4/data" using 1:2,
"folder4/data" using 1:3
This should be closer to what you were looking for based on your comment.