0

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) ?

warren
  • 32,620
  • 21
  • 85
  • 124

2 Answers2

1

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

Aaron Anodide
  • 16,906
  • 15
  • 62
  • 121
0

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
  • 2,068
  • 2
  • 15
  • 18