The tee program does exactly what you want. It reads from stdin and displays the data on the terminal, while redirecting it to a file. This is an old UNIX tool and is also available with GNU coretutils .
Redirect the output of process to a file and simultaneously display it on the terminal:
process | tee output.file
If you want to add output.file to the file, use the -a option:
process | tee -a output.file
source share