I want to locate all text-files within a directory tree containing two words, word1
and word2
(for example). I cannot just grep
for word1 word2
, because this will only find occurrences where the two words appear consecutively. I want to find all files that contain both these two words, but not necessarily consecutive.
Ideally, the search should print file names as well as the context where the terms were found inside the files. This would be very helpful. A GUI wouldn't hurt.
How can I do it?
grep -E -C 3 'word1|word2' $(list of files that contain both strings)
show the sort of context you want? – Mark Plotnick Apr 23 '18 at 18:37