I have a script that outputs text to stdout
. I want to see all this output in my terminal, and at the same time I want to filter some lines and save them in a file. Example:
$ myscript
Line A
Line B
Line C
$ myscript | grep -P 'A|C' > out.file
$ cat out.file
Line A
Line C
I want to see output of first command in terminal, and save the output of the second command in a file. At the same time. I tried using tee
, but with no result, or better, with reversed result.
/dev/stderr
is common./dev/tty
(meaning the current terminal) would also work here, and it's standard. – Gilles 'SO- stop being evil' Apr 06 '13 at 23:42tee /dev/tty
served wonderfully for my requirement of having to print thestdout
of a script to terminal and to pipe it to thestdin
of another command as well! Thankees! :-) – jamadagni Jun 07 '14 at 01:09/dev/tty
doesn't work on non-interactive terminals it appears. I gottee: /dev/tty: No such device or address
when automating this on a server, but worked fine locally. – Elijah Lynn Oct 09 '20 at 02:15myscript
is running in the background (as it presumably would be on a server), then the process doesn't have a terminal to output to unless you provide one -- which if/dev/tty
is "the current terminal" and there isn't one, of course it doesn't work. -> XY problem – goldilocks Oct 09 '20 at 14:02