I try to write a script which will be executed by the shell to use several txt-files in a directory to plot multiple lines in a graph with gnuplot. So if I type in the command for one picture, the results are as imagined. Here you can see the command:
plot "test2.txt" using 2:1 w filledcurves lc "red" title "Red Channel", "text2.txt" using 3:1 w filledcurves lc "green" title "Green Channel", "text2.txt" using 4:1 w filledcurves lc "blue" title "Blue Channel"
Now my Script looks like this:
[...] for i in 'ls -1 *.txt' do cat $1| tr ":()" " " | gnuplot -p -e 'set terminal jpeg; set output "'$1'.jpeg";plot "/dev/stdin" using 2:1 w filledcurves lc "red" title "Red Channel", "/dev/stdin" using 3:1 w filledcurves lc "green" title "Green Channel", "/dev/stdin" using 4:1 w filledcurves lc "blue" title "Blue Channel"' done
The script edits every txt-file and creates a jpg but only with the first graph, the “Red Channel”. I also tried it alternativly with a seperation like ,
between the different lines but it didn’t work. Also tried to use just ''
instead of “/dev/stdin” but nothing happend then at all.
Advertisement
Answer
What you are trying to do won’t work because your first plot
will consume the entire stdin
. There are also other problems. I am not at a computer to test, but I think you’ll be closer with:
for i in *.txt ; do tr ‘:()’ ‘ ‘ < “$i” > /tmp/a.txt gnuplot -pe ‘set terminal jpeg; set output “/tmp/a.jpg”; plot “/tmp/a.txt” ... ‘ mv /tmp/a.jpg “${i}.jpeg” done