How to search multiple search patterns from a file with grep

command linegrepregular expressionsearch

If I search for multiple search strings in grep : usually just do:

grep "search1\|search2" somefolder/*.txt

but, what if I have 100 or more search strings? Can I say like this:

grep "stringPattern.txt" somefolder/*.txt

where stringPattern.txt is a file containing a list of words I need to search in *.txt.

Best Answer

grep has the -f flag exactly for this, use:

grep -f patternfile somefolder/*.txt

Where in the patternfile the search patterns are separated line by line.

Related Question