I am looking for a command options for grep to
find files with the occurences of foo and bar.
Grepping with
grep -r -e foo -e bar .
shows files which have only foo or only bar and files which have foo and bar.
Is it possible with grep to find only files which have both foo and bar (and display the lines that match either foo or bar or both in those files only)?
Example:
echo foo > file1
echo bar > file2
(echo foo;echo;echo bar) >file3
echo barfoo > file4
the grep cmd:
grepcmd -r -e foo -e bar .
./file3:foo
./file3:bar
./file4:barfoo
fooandbar, I want to have listed the files and the lines withfooandbarlike I'd search for only one string. – Feb 07 '14 at 19:48agrep, anyways where you find this tool ? – Rahul Patil Feb 07 '14 at 19:58ais for approximate which is its main feature (one you'd expect from a search engine like htdig). – Stéphane Chazelas Feb 07 '14 at 20:00grep -rl --null abc . | xargs -r0 grep -l --null bcd | xargs -r0 grep -He abc -e bcdnot answering the question? (replace abc, bcd with foo, bar)? – Stéphane Chazelas Feb 07 '14 at 22:44ht://dig, that was glimpse. Bad memory. – Stéphane Chazelas Sep 06 '16 at 05:52