How can we use grep
to get line(s) containing a group of words, while the order of words is not important, although line(s) should contain all words mentioned in search?
I have done that with phasing the search (with piping, saving the outputs in temporary files, and searching again), but I'd like to know if I can do that in one attempt.
Here is a sample; I want to search in the lines below for lines containing sample, words, list:
it's a sample test file for a list of words.
list of words without a specific order, it's a sample.
line with no search keyword here.
list the sample files.
something completely different.
And get this result:
it's a sample test file for a list of words.
list of words without a specific order, it's a sample.
grep -e words -e sample -e list newfile
works as wellawk
better fits here.awk '(/sample/ && /words/ && /list/)' samplefile