[PLUG] find | while read
Eric Wilhelm
scratchcomputing at gmail.com
Sun Apr 13 06:11:11 UTC 2008
# from Stuart Jansen
# on Saturday 12 April 2008 09:12:
>find . -name '*.txt' | \
>while read FILE
>do
> echo Spell checking $FILE
> aspell -c "$FILE"
>done
Right. You can't have your stdin and have your stdin too.
$ echo 'a
b
o q' | while read FILE; do perl -e 'while(my $line = <STDIN>) {
warn "I ate your $line"}'; done
I ate your b
I ate your o q
So, if your loop command expects STDIN to be a TTY, xargs -d '\n' -n 1
won't help either unless you want to find a way to stick a terminal
between the xargs and the command:
find . -name '*.txt' | xargs -d '\n' -n 1 xterm -e aspell -c
Alternatively, you could do it in perl with the find (git) command as a
piped open fork, thus the parent process still has a STDIN to lend to
the aspell.
perl -e '
open(my $fh, "-|", qw(find . -name *.txt));
while(my $file = <$fh>) {
chomp($file);
system(qw(aspell -c), $file) and die "ouch";
}
'
--Eric
--
Minimum wage help gives you minimum service.
--David Schomer
---------------------------------------------------
http://scratchcomputing.com
---------------------------------------------------
More information about the PLUG
mailing list