Matching an array of strings to strings in a file.

Aaron Crane perl at
Mon Aug 29 13:03:34 BST 2011

Martin A. Brooks <martin at> wrote:
> I have an array of strings.  I have some plain text files on disk.  I want to see if any of the lines in the text files contain any of the strings in the array.  I can stop as soon as I find one match.

Does this work for you?

$ grep -F -q -e needle1 -e needle2 -e needle3... haystack/*.txt

You may find it simpler to put the needles in another file, one per
line, and use `-f needles.txt` instead of the multiple `-e` options,
especially if you have a very large number of needles.

Aaron Crane **

More information about the mailing list