I want to write part of the results of a stream to a file, but I want the entire contents of the stream printed to the console. Is there some command that would help with this?
Minimal example:
Say I had a file foo.txt
with contents:
bat
dude
rude
And I wanted to write all lines in that file which contain the letter 'a' to bar.txt
. I could write
cat foo.txt | grep 'a' > bar.txt
Which would result in bar.txt
containing bat
. But that wouldn't give me the console output that I want.
Instead I would prefer something like:
cat foo.txt | output-stdin-to-console-and-pass-to-stdout | grep 'a' > bar.txt
Which would not only write bat
to bar.txt
but also write the following to the console:
bat
dude
rude
Is there any command I can run to do that?