views:

772

answers:

1

I have a fairly simple bash script that does some grep to find all the text in a file that does not match a pattern.

grep -v $1 original.txt >trimmed.txt

The input file ends each line with the Windows line end characters, i.e., with a carriage return and a line feed CR LF.

The output of this command (run in Cygwin) ends each line with an extra carriage return, i.e., CR CR LF.

How do I tell grep to just use CR LF?

+3  A: 

I think you can only configure the EOL setting during Cygwin install.

If you run your original file through dos2unix first, then grep should be able to process properly (you may wish to run through unix2dos afterwards to revert the EOLs)

Brian Agnew
Thanks! I must have my Cygwin EOLs badly configured, because it works fine even when I don't do unix2dos after. This is all I needed to get it to work. 1: dos2unix original.txt 2: grep -v $1 original.txt >trimmed.txt
dtjohnso