transform stream sent to a file by tee

Viewed 52

I want to redirect the stdout and stderr of a stream both to the screen and a file. For that I'm using the tool tee. However, before that stream goes to the file, I want to transform it using a pipe. So far, I have only managed to transform the stream that goes to stdout.

Example:

echo 'hello' | tee output.txt | tr 'h' 'e'

=> this will output eello to stdout and save hello to output.txt

However what I want is to print hello to stdout and save eello to output.txt.

Note: Changing the input stream is not an option for my problem.

2 Answers

You can do that in a single awk without multiple pipes:

echo 'hello' | awk '1; {gsub(/h/, "e"); print > "output.txt"}'
Related