|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
Consider this: -------- cat make_graphs echo "Creating 2D-plots at each timestep" for file in splot*.txt; do echo "splot \"$file\" w lines" > temp.txt; gnuplot plot_header.txt temp.txt epstopdf gnuplot.eps echo Making ${file%.txt}.pdf mv gnuplot.pdf ${file%.txt}.pdf done echo echo "Creating temperature profile" gnuplot plot_commands.txt epstopdf gnuplot.eps echo echo "Deleting temp-files" rm temp.txt rm gnuplot.eps -------- I made that, but I'm not very experienced, so for instance this line: do echo "splot \"$file\" w lines" > temp.txt; Is that the right method? The \" comes from my c-programming habits. It looks like it works in bash too... Sometimes I see you guys discuss something about: What if $file has a space in it? Will it work too? I'm also writing to temp.txt in each run... Perhaps I can avoid that? I was pretty lucky about the: echo Making ${file%.txt}.pdf Because I remember I had seen something like that once... Could somebody please remind me: If I wanted to remove the first part of the file, (until the .txt part) how is it you do that? I forgot it... Best regards Martin Jørgensen -- --------------------------------------------------------------------------- Home of Martin Jørgensen - http://www.martinjoergensen.dk |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
2006-12-06, 23:05(+01), Martin Jørgensen:
> Hi, > > Consider this: > -------- > cat make_graphs > echo "Creating 2D-plots at each timestep" > > for file in splot*.txt; > do echo "splot \"$file\" w lines" > temp.txt; > gnuplot plot_header.txt temp.txt > epstopdf gnuplot.eps > echo Making ${file%.txt}.pdf > mv gnuplot.pdf ${file%.txt}.pdf > done for file in splot*.txt do printf 'split "%s" w lines\n' "$file" | cat plot_header.txt - | gnuplot && printf 'Making "%s"\n' "${file%.txt}pdf" && epstopdf --outfile="${file%txt}pdf" gnuplot.eps done [...] > do echo "splot \"$file\" w lines" > temp.txt; > > Is that the right method? The \" comes from my c-programming habits. It > looks like it works in bash too... Sometimes I see you guys discuss > something about: That's allright except for your usage of echo which is a non-portable non-reliable commande. > What if $file has a space in it? Will it work too? If you qupte variables yes. Depending on the syntax of gnuplot, you'll probably have troubles for files whose name contains ", \ or newline characters (because of the split "$file"). > I'm also writing to > temp.txt in each run... Perhaps I can avoid that? Yes. > I was pretty lucky about the: > > echo Making ${file%.txt}.pdf you need to quote any ${...} echo "Making ${file%.txt}.pdf" > Because I remember I had seen something like that once... Could somebody > please remind me: If I wanted to remove the first part of the file, > (until the .txt part) how is it you do that? I forgot it... That would be in your shell manual. ${file##*.} would delete up to the "." -- Stéphane |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Stephane CHAZELAS <this.address@is.invalid> writes:
> 2006-12-06, 23:05(+01), Martin Jørgensen: >> Hi, >> >> Consider this: >> -------- >> cat make_graphs >> echo "Creating 2D-plots at each timestep" >> >> for file in splot*.txt; >> do echo "splot \"$file\" w lines" > temp.txt; >> gnuplot plot_header.txt temp.txt >> epstopdf gnuplot.eps >> echo Making ${file%.txt}.pdf >> mv gnuplot.pdf ${file%.txt}.pdf >> done > > for file in splot*.txt > do > printf 'split "%s" w lines\n' "$file" | > cat plot_header.txt - | > gnuplot && > printf 'Making "%s"\n' "${file%.txt}pdf" && > epstopdf --outfile="${file%txt}pdf" gnuplot.eps > done > > [...] Aha... Thanks. But the file-name is not inserted correctly (I assume you meant splot instead of split?): --- $ ./make_graphs Creating 2D-plots at each timestep gnuplot> splot "splot*.txt" w lines ^ can't read data file "splot*.txt" line 0: util.c: No such file or directory Creating temperature profile gnuplot> splot "gnuplot.txt" with lines ^ can't read data file "gnuplot.txt" "plot_commands.txt", line 15: util.c: No such file or directory ==> Warning: BoundingBox not found! Deleting temp-files --- So it obviously inserted file "splot*.txt" but I think the program can only handle 1 file at a time: splot000.txt, splot001.txt, splot 002.txt, etc. in order... >> Is that the right method? The \" comes from my c-programming habits. It >> looks like it works in bash too... Sometimes I see you guys discuss >> something about: > > That's allright except for your usage of echo which is a > non-portable non-reliable commande. Thanks. >> What if $file has a space in it? Will it work too? > > If you qupte variables yes. Depending on the syntax of gnuplot, > you'll probably have troubles for files whose name contains ", \ > or newline characters (because of the split "$file"). Can a file contain a newline character? Really? Ok, but that is not a problem though, because I choose the filenames myself. Only to learn I bit more, I asked... >> I'm also writing to >> temp.txt in each run... Perhaps I can avoid that? > > Yes. > >> I was pretty lucky about the: >> >> echo Making ${file%.txt}.pdf > > you need to quote any ${...} Ok. > echo "Making ${file%.txt}.pdf" > >> Because I remember I had seen something like that once... Could somebody >> please remind me: If I wanted to remove the first part of the file, >> (until the .txt part) how is it you do that? I forgot it... > > That would be in your shell manual. ${file##*.} would delete up > to the "." Thanks... Best regards Martin Jørgensen -- --------------------------------------------------------------------------- Home of Martin Jørgensen - http://www.martinjoergensen.dk |
|
![]() |
| Outils de la discussion | |
|
|