0

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?

2 Answers 2

2

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
0
0

Test it by reducing the complexity of the command. Try this first:

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

If that works, then the problem is with your dynamic file-name-creation code. Perhaps this would work:

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

What is the f% trying to do? Should that be $f instead?

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

1
  • None of the commands work! On the first and second command, the error is: Expecting zero one 1 arguments. Got 9, etc. On the third command, the error is Bad substitution. Hey, I thought this would be simple to do. It is turning out to be quite complex!
    – deshmukh
    Jul 21, 2012 at 7:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .