Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm doing some stream processing of some quite substantial files-- I was wondering if there was a way to split stdout in order to pipe to multiple programs. What I'd like to do is something like this:

bzcat some_huge_file.bz2 | (wc > wordcount, char_stats > character_statistics) 

I could write this glue in something like perl or python, but it seems like there ought to be a way to do this.

Google brings me to tpipe, but I can't find any copy of tpipe or sources (nothing local on OS X 10.8).

share|improve this question
3  
Found it- I don't have enough rep to post the answer outside a comment: The answer is tee and "process substitution". bzcat some_huge_file.bz2 | tee >(wc > wordcount) | char_stats > character_statistics –  Matthew G. Dec 21 '12 at 17:58
    
I hope you will be able to post your answer 48 hours after posting your question, without rep issues. –  pnuts Dec 21 '12 at 18:41
add comment

1 Answer

up vote 3 down vote accepted

Converting the poster's comment into a formal answer:

The answer is tee and "process substitution".

Example

bzcat some_huge_file.bz2 | tee >(wc > wordcount) | char_stats > character_statistics
share|improve this answer
    
It does however seem, that at least on OS X Lion, this results in some gently unexpected results-- Specifically, from what I've seen, it appears that the output of the process-substituted command (wc above) gets mixed with the input into the last command there (char_stats above) –  Matthew G. Jan 9 '13 at 20:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.