Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

1 Answer 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
share|improve this answer
    
That was it. Another option is to use NotePad++ to save in Unix text format. –  Roy Jensen Nov 26 '12 at 20:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.