On occasion I need to search for a specific string within several files, but the results are only relevant if those files contain a second specific string, not necessarily on the same line as that first specific string.
1 Answer
grep -ril 'string 1' * | xargs grep -rin 'string 2'
The -l includes only file names rather than the matching lines themselves. The xargs reads the files to search from the standard output of the first grep.