Use process substitution:
Code:
ls | tee >(grep example >> example.txt)
The >(...) syntax creates a named pipe. tee will write to this pipe and to the terminal, the shell connects standard input of whatever is in the parentheses to the reading end of the pipe.
Edit: An interesting example I occasionally run:
Code:
cat file1.tex file2.tex file3.tex | sed -f glsstuff.sed.00 | sed -f glsstuff.sed.01 | sed -f filter.sed | \
tr -s ' ' '\n' | tr '[:upper:]' '[:lower:]' | sed /^$/d | sort | tee >(uniq -c | sort -no wordfreq.txt) | uniq | \
tee wordlist.txt | while read w; do echo ${#w} $w; done | sort -no wordlength.txt
This reads a bunch of .tex files, runs them through some filters and uses tee to generate three word lists: all words by frequency, alphabetically and by length. Note the process substitution on the second line.
Bookmarks