Pipelines run from left to right. More precisely, the processes run in parallel, but the data flows from left to right: the output of the command on the left becomes the input of the command on the right.
Here the command on the left is grep tool
. Since you're passing a single argument to grep
, it's searching in its standard input. Since you haven't redirected the standard input, grep
is reading from the terminal: it's waiting for you to type.
To search in a file, use
grep tool path/to/file | …
To search in a directory recursively, use
grep -r tool path/to/directory | …
You can filter the results to list only the lines that contain embed=
. Drop the -l
and -r
options, they make no sense when the input is coming from standard input.
grep -r tool path/to/directory | grep 'embed='
This lists lines containing both tool
and embed=
(in either order). An alternative method with simpler plumbing would be to do a single search with an or pattern; this is always possible, but if the patterns can overlap (not the case here), the pattern can get very complicated.
grep -E -r 'tool.*embed=|embed=.*tool' path/to/directory
If you wanted to list files containing both tool
and embed=
, you'd need a different command structure, with the first grep
listing file names (-l
) and the second one receiving those file names as arguments, not as input. Converting standard input into command line arguments what the xargs
command is for.
grep -lZ -r tool path/to/directory | xargs -0 grep -l 'embed='
grep
needs a file (or stdin using a pipe) to read from. – polym Apr 11 '16 at 16:55grep tool
is looking for wordtool
in thestdin
, then you are looking for file names, recursively, contaning keywordembed=
. This can not possibly yield anything for you. If you haven't thought about it, second grep is taking first one's output as its input. If that input is just lines,-r
or-l
switches are irrelevant. – MelBurslan Apr 11 '16 at 16:58stdin
andstderr
? – Xiong Chiamiov Apr 11 '16 at 23:39