Linguist
Linguist

Reputation: 123

Passing/Piping of multiple output generated from a program into other followed program in bash

So, basically what I am concerned at: I want the search results found by grep to be piped into next program and also use the number of search results done by "wc -l" again in next program itself.

**| grep 'logprob' | wc -l | ***Next Code seeking logprob results & size***

P.S: grep command is also working on the input files piped to it.

Upvotes: 0

Views: 36

Answers (1)

William Pursell
William Pursell

Reputation: 212248

... | grep logprob | { tee /dev/stderr | wc -l; } 2>&1 | ...

This will write the total number of lines after all the lines have been written, so is not particularly useful (the consuming program will already know the number of lines that it read), but you can use a file:

... | grep logprob | { tee /tmp/file | wc -l; cat /tmp/file; rm /tmp/file; } | ...

And now the line count will be the first line available to the consumer.

Upvotes: 2

Related Questions