Friday, April 19, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 3581  / 12 Months ago, sat, may 20, 2023, 6:02:31

When I want to process a bunch of tex files, I use



for f in *.tex; do latex "$f" ; done;


What do I do when I need to redirect output to another file, like in case of catdvi?



The following does not work:



for f in *.dvi ; do catdvi -e 1 -U $f  > "${f%.dvi}.txt"; done;


What am I doing wrong?


More From » bash

 Answers
6

You forgot to quote $f, so the filename probably got wordsplit due to whitespace in the filename. I also suggest using ./*.dvi as this avoid problems if a filename starts with a - (which will make most commands treat it as a set of options instead of a filename)



for f in ./*.dvi; do catdvi -e 1 -U "$f" > "${f%.dvi}.txt"; done


Or perhaps combine the two loops



for f in ./*.tex; do 
base=${f%.tex};
latex "$f" &&
catdvi -e 1 -U "$base.dvi" > "$base.txt";
done

[#36717] Saturday, May 20, 2023, 12 Months  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ormlai

Total Points: 292
Total Questions: 106
Total Answers: 115

Location: Cape Verde
Member since Fri, Sep 16, 2022
2 Years ago
ormlai questions
Wed, Sep 28, 22, 00:17, 2 Years ago
Sun, Aug 7, 22, 22:05, 2 Years ago
Wed, Jun 16, 21, 03:50, 3 Years ago
Sun, Feb 6, 22, 09:11, 2 Years ago
Mon, Jul 12, 21, 10:00, 3 Years ago
;