Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Found out that tee is a possible way. Is this the way for the particular task? – dr_dom Feb 25 '13 at 19:35
up vote 5 down vote accepted

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

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

share|improve this answer
This command won't work unfortunately as "tee" dumps a copy of the output to a file, and another to stdout. (And yes, I tried it just to make sure this did not work as posed above) – davidgo Feb 25 '13 at 21:19
tee can take multiple files as arguments (which is how the two process substitutions appear to tee). You can redirect tee's standard output to /dev/null as well. – chepner Feb 25 '13 at 21:25
Here's a concrete example that prints foo three times: echo foo >(cat) >(cat). If you don't want the output, here's one that prints foo twice: echo foo|tee >(cat)|cat. – Stephen Niedzielski Jun 10 at 23:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .