Cygwin grep and -f switch

1

I've created a text file (in Windows) with the text patterns I wish to search for. Using the -f switch, grep only searches for the last pattern in the list. If there is a blank line, grep finds nothing.

grep -a -A 4 -f Grep.txt my.file

Any suggestions to get this to work?

Thanks

Roy Jensen

Posted 2012-11-26T18:52:21.200

Reputation: 11

Answers

1

Check to be sure each line in your pattern file ends with only a \n character Unix-style, not a Windows-style \r\n combination. To the Cygwin grep, a \r is an ordinary character that it would try to match.

You can delete the \r characters with tr:

tr -d "\r" < infile > outfile

Nicole Hamilton

Posted 2012-11-26T18:52:21.200

Reputation: 8 987

That was it. Another option is to use NotePad++ to save in Unix text format. – Roy Jensen – 2012-11-26T20:12:55.150