Hi, I have an N number of files in a directory. I like to write a shell script that would make identical plots for each one of these files.
The files have names such as:
t00001.dat
t00002.dat
t00003.dat
t00004.dat
t00005.dat
.
.
.
t00040.dat
i.e. the filename is incrementing numerically from a value of 1 to N.
I plot some variables from these files using gnuplot. So in my gnuplot plotting script (plot.gplt) I have the following line which plots the function:
plot 't00001.dat' using 1:2
I know that using a perl script I could change the filename 't00001.dat' incrementally. But with my limited knowledge in shell scripting I don't know how to do this.
Thanks!
Yoda
December 6, 2012, 12:19pm
2
How about:-
printf "%s\n" t*.dat | sort | while read file
do
plot '"$file"' using 1:2
done
1 Like
for file in t*.dat
do
plot "'$file'" ...
done
1 Like
for i in {1..40};
do
str=$(printf %05d $i)
plot \'"t$str.dat"\' using 1:2
done
1 Like
Thanks for the replies. I'm sorry I didn't explain my problem clearly.
I have a gnuplot script file that does the plotting (called time.gplt), in it I have the following line that plots the data.
plot 't00001.dat' using 1:2
Using rdcwayx's method I've been able to do most of what I want, i.e:
for i in {1..40};
do
str=$(printf %05d $i)
perl -i -pe "/plot/&&s/t\d+/t$str/" time.gplt
gnuplot time.gplt
done
But now I have the following questions
1) is it possible to use something like
n=$(ls -l t?????.dat | wc -l)
to calculate the number of files and then use that to define the number of loops?
2) Also I have the following line in my gnuplot script (time.gplt) which I would like to modify:
set label at 14,10 '$t=1.0$~ms'
I would like to replace the number after the equal sign in the above code with the variable $str?
Thanks!