grep multiple - find files containing multiple patterns

A little while ago I needed to search for all files in a CVS repository that contain multiple character patterns (i.e., I wanted to be able to grep multiple patterns in multiple files).

In my case these patterns were "prevayl" and "jtable". I couldn't find a way to do this with a simple combination of the find and grep commands, but a friend suggested this grep/find command:

grep -li "jtable" $(find . -name "*.java,v" -exec grep -li "prevayl" {} \;)

This grep command begins inside the parentheses by first finding all files whose name ends with the characters "*.java,v" and also contains the string "prevayl". Once it finds those files the find command prints the file names, and then the grep command kicks in to find the string "jtable".

There may be better ways of doing this, but for today it worked as an okay solution to grep multiple patterns on many files, in many directories.

Post new comment

The content of this field is kept private and will not be shown publicly.