5
3
I often find myself searching through a bunch of code using grep in order to pin down what I'm looking for. Sometimes I get a list of files a little longer than I hoped. At this point I want to perform a second grep, but only searching through the files returned by the first grep search. Is there a way to do this? I basically want to cross-reference two grep searches and only get back the files with both results contained within them.
Awesome thank you. Can you enlighten me as to what
xargs
is? – Chev – 2014-08-04T17:26:46.2072
@AlexFord - from the
– jimm-cl – 2014-08-04T17:35:40.297xarg
's Wikipedia article, xargs is a command on Unix and most Unix-like operating systems used to build and execute command lines from standard input.. In other words, it allows you to use the results from a command as the standard input to another. Try to use the same commands but withoutxargs
, and you will see the problem (grep -l "first string" * | grep -l "second string"
)What is the problem with that command line? I don't have an OS X or Linux system at hand to test on. – ntoskrnl – 2014-08-04T19:51:36.823
1
@ntoskrnl - you will get a "
– jimm-cl – 2014-08-04T20:01:39.323(standard input)
" message. A good explanation is this one, from Joseph R.2@jim "it allows you to use the results from a command as the standard input to another" No, that's what piping does. xargs lets you use the results from a command as the arguments to another. – Ajedi32 – 2014-08-04T20:04:47.767
1@Ajedi32 - you are correct - my bad. Edited answer :-) Thanks! – jimm-cl – 2014-08-04T20:11:56.767