Regex – Grep regular expression to find words in any order


Context: I want to find a class definition within a lot of source code files, but I do not know the exact name.

Question: I know a number of words which must appear on the line I want to find, but I do not know the order in which they will appear. Is there a quick way to look for a number of words in any order on the same line?

Best Solution

For situations where you need to search on a large number of words, you can use awk as follows:

awk "/word1/&&/word2/&&/word3/" *.c

(If you are a cygwin user, the command is gawk.)