Question

I can extract the contents of all the \include statements from a latex file (and append ".tex" to each one) with

grep -P "\\\\include{" Thesis_master.tex |sed -n -e"s/\\\\include{/$1/" -e" s/}.*$/.tex/p"

(I couldn't get lookbehinds working in grep, hence the pipe through sed. That gives me a list of filenames, one per line. I'd now like to pass those files to aspell. But aspell only accepts one filename as an argument, so I can't just tack |xargs aspell -c on the end.

I've read this related question but that reads from a file line by line through xargs. So how do I get it to read from the output of sed line by line?

Was it helpful?

Solution

I think xargs -L 1 should do what you need:

grep -P "\\\\include{" Thesis_master.tex | \
sed -n -e"s/\\\\include{/$1/" -e" s/}.*$/.tex/p" | \
xargs -L 1 aspell -c

(Backslash line continuation added for readability)

This will cause xargs to call aspell exactly once per line from the sed pipe.


Since your aspell commands appear to exit with a 255 code, this causes xargs to stop. You could trick xargs into not exiting by doing something like:

grep -P "\\\\include{" Thesis_master.tex | \
sed -n -e"s/\\\\include{/$1/" -e" s/}.*$/.tex/p" | \
xargs -L 1 -I % bash -c "aspell -c %; true"

This will run aspell in a subshell, followed by the true command which always return a 0 exit code to xargs.

OTHER TIPS

The grep recipe is:

grep -oP '\\include{\K.+?(?=})' latex.file | xargs aspell ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top