Is there a way to process text from tee before it sent to a file?
For example, if a program outputted the following lines:
stack 11
stack 22
stack 33
serverfault
serverfault
stack 44
How could I send only the lines that contain "stack" to a file, while still displaying the original output from the program via stdout?
I'm not sure whether it would even be possible to do this using tee, so I am open to any other suggestions.
Thanks
To display the full output of myprogram on the terminal while saving filtered output to a file:
myprogram | tee /dev/tty | grep stack >out
If you didn't want to send the full output to your terminal but instead wanted to process it with something else, say someotherprogram, then we can use bash's process substitution:
myprogram | tee >(grep stack >out) | someotherprogram
someotherprogram receives the full output of myprogram on its stdin while only filtered output is saved in out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With