After clarification:
The solution by Daniel Schelper is the correct one on normal human usable shells (google Why never to use csh). Unfortunately sometimes we do not have a choice, so one solution:
perl test.pl | tee /dev/stderr | sed 's/\x1b\[[0-9;]*m//g' > test.log
What this does is duplicate stdout
to stderr
, and pipes only stdout
forward. The output from perl
will be displayed on screen (through stderr
). This has the obvious caveat that any real errors may be hidden. A safer solution may be:
perl test.pl > /tmp/temp.log; cat /tmp/tmp.log & sed 's/\x1b\[[0-9;]*m//g' /tmp/tmp.log
which of course makes an extra file. The good options on csh usually involve more intermediate files compared to Bourne shells.
Old answer
tee
should always be the last piped program (unless you want to log something midway I guess), and have a filename as an argument. The former is because the whole point is to see the output in the screen (not pass it on) and the second is because tee is usually not useful when it doesn't send output to a file as well.
As it currently stands, you are passing stdout
through tee
to the next pipe, sed
, and that is dumping everything into test.log
with the >
operator. In fact, you should not have both >
and tee
:
perl test.pl | sed 's/\x1b\[[0-9;]*m//g' | tee test.log
to get results of sed
both on screen and in your log. If I misunderstand and you in fact do want to log the results midway using tee
perl test.pl | tee mid.log | sed 's/\x1b\[[0-9;]*m//g' > test.log