I want to make a shell-pipe like this:
producer | analyser > report.txt
and watch the output of producer while it is generating data (a big log-file) for analysis.
How can I do that?
I want to make a shell-pipe like this:
producer | analyser > report.txt
and watch the output of producer while it is generating data (a big log-file) for analysis.
How can I do that?
In /bin/sh and compatibles:
producer | tee /dev/fd/3 | (analyser > report.txt) 3>&1
I've tested this only on Linux and Cygwin.
On some Unix-likes you may have to change /dev/fd/3 to whatever their equivalent is.
/dev/fd/3, I believe to have learned that3isn't defined, and therefore doesn't work everywhere, while/dev/fd/2sends the output to stderr, which isn't sent into the pipe by default. – not2savvy Dec 10 '22 at 14:48sh -c 'echo hello 1>&3 && ls -l /dev/fd/' 3>&1and you will see/dev/fd/3. – reinierpost Dec 10 '22 at 18:56