Reading the same stdin with two commands in bash

bashpipe

I would like to pipe an output of to two separate commands <2,3> in bash. What is the best way of doing this? At the moment, I have following script:

command source > output
command2 output &
command3 output &

The output file is ~100G and a suboptimal way would be to pipe to commands 2 and 3 separately. I would think it is possible to do even more efficiently.

Best Answer

In bash: command source | tee >(command2) >(command3)

From this stackoverflow question. I haven't tried this with ginormous outputs.

Related Question