How do I pipe the output of grep as the search pattern for another grep?
As an example:
grep | xargs grep
If using Bash then you can use backticks:
> grep -e "`grep ... ...`" files
the -e
flag and the double quotes are there to ensure that any output from the initial grep
that starts with a hyphen isn't then interpreted as an option to the second grep
.
Note that the double quoting trick (which also ensures that the output from grep is treated as a single parameter) only works with Bash. It doesn't appear to work with (t)csh.
Note also that backticks are the standard way to get the output from one program into the parameter list of another. Not all programs have a convenient way to read parameters from stdin the way that (f)grep does.