Code:
grep --version # grep (GNU grep) 3.7
search 1000s of files looking for:
4 words in any file
4 words in any order
4 words have unknown # of words inbetween each
4 words might have a prefix: tree, blacktree
4 words might have a suffix: dog, dogs
Objective
find all files that contain 4 words in any order.
Sample
Text file has many Lines, here are 2 Lines:
Line 3 = tree and claws or dog maybe paws .
Line 4 = trees and zclaws or dogs maybe zpaws .
This works
Code:
time grep -Eri '.*tree.* .*claws.* .*dog.* .*paws.*'
Dir1/Dir2/filename.txt:Line 3 = tree and claws or dog maybe paws .
Dir1/Dir2/filename.txt:Line 4 = trees and zclaws or dogs maybe zpaws .
But this does not work:
Code:
time grep -Eri '.*claws.* .*dog.* .*paws.* .*tree.*'
the above changes the order of the words
tree was the 1st word in grep now
tree is the 4th word in grep.
Thus, changing the order of the word fails to find the file.
How to structure grep command?
so order of words does not matter.
-
Comment