Passing a file with multiple patterns to grep

Posted by Michael Goldshteyn on Server Fault See other posts from Server Fault or by Michael Goldshteyn
Published on 2010-10-26T14:28:41Z Indexed on 2011/01/09 6:54 UTC
Read the original article Hit count: 351

Filed under:
|
|

Let's say we have two files.

match.txt: A file containing patterns to match:

fed ghi
tsr qpo

data.txt: A file containing lines of text:

abc fed ghi jkl
mno pqr stu vwx
zyx wvu tsr qpo

Now, I want to issue a grep command that should return the first and third line from data.txt:

abc fed ghi jkl
zyx wvu tsr qpo

... because each of these two lines match one of the patterns in match.txt.

I have tried:

grep -F -f match.txt data.txt

but that returns no results.

grep info: GNU grep 2.6.3 (cygwin)
OS info: Windows 2008 R2

Update: It seems, that grep is confused by the space in the search pattern lines, but with the -F flag, it should be treating each line in match.txt as an individual match pattern.

© Server Fault or respective owner

Related posts about Windows

Related posts about command-line