2

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?

sblair
  • 12,617
  • 6
  • 48
  • 77
Bastl
  • 213
  • 2
  • 11

1 Answers1

5

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.

reinierpost
  • 2,220
  • 1
  • 18
  • 23
  • that will show and save the output of analyser, right? I want to see the output of producer. – Bastl Feb 10 '12 at 12:12
  • sorry - better now? – reinierpost Feb 10 '12 at 12:14
  • That will save producer's output to report.txt and I'd have to watch it using "tail -F". Not exactly what I wanted... – Bastl Feb 10 '12 at 12:16
  • Fixed once again. I should learn to actually read stuff before replying. – reinierpost Feb 10 '12 at 12:25
  • 1
    On Ubuntu, I had to use /dev/fd/2 for stdout. Thanks! – Bastl Feb 10 '12 at 13:33
  • Trying to understand `/dev/fd/3`, I believe to have learned that `3` isn't defined, and therefore doesn't work everywhere, while `/dev/fd/2` sends the output to stderr, which isn't sent into the pipe by default. – not2savvy Dec 10 '22 at 14:48
  • Indeed, numbers 3 and up don't exist by default. Try running `sh -c 'echo hello 1>&3 && ls -l /dev/fd/' 3>&1` and you will see `/dev/fd/3`. – reinierpost Dec 10 '22 at 18:56