tags:

views:

16

answers:

2

Consider this example chain:

cat foo.txt | grep -v foo | grep -v bar | grep -v baz

I'd like to inspect the contents stdout of the second grep as well as the resulting stdout:

cat foo.txt | grep -v foo | grep -v bar | UNKNOWN | grep -v baz

So I need a tool, UNKNOWN, that for instance dumps the contents of stdout to a file and also passes stdout along the chain.

Does the tool, UNKNOWN, exists (both Windows and Linux answers are relevant) ?

+1  A: 

I think there's a thing call 'tee' that gives you that.

Update reflecting comment from Bob: cat foo.txt | grep -v foo | grep -v bar | tee -a inspection.txt | grep -v baz

Gabriel
cat foo.txt | grep -v foo | grep -v bar | tee -a inspection.txt | grep -v baz
Bob the Builder
A: 

Unable to give it a shot, but like Gabriel and Bob pointed out, the command $ tee (man tee) will help you out. The tee command will take input and echo it to stdout, as well as files. As Bob said in his comment:

cat foo.txt | grep -v foo | grep -v bar | tee -a inspection.txt | grep -v baz

Will take the output from grep -v bar and put it to stdout, as well as inspection.txt. The -a flag causes it to append to inspection rather than create a whole new file.

Bryan