0

A couple of days ago I installed cygwin. I checked that grep was installed since I wanted to use it in emacs. When I wanted to obtain the difference between two files it didnt seem to work so I tried the simplest case scenario that didnt work using only the cygwin terminal.

I have two files temp1

1
2
3
4
5
6
7
8
9
0

temp2

2
3
4
5

After looking around I found that the way to do it correctly was like this:

grep -v -f temp2 temp1

When I do it in cygwin I get

1
2
3
4
5
6
7
8
9
0

whereas if I do it in linux I get the correct output

1
6
7
8
9
0

Why could this be happening? Its probably something really silly but I cant seem to find the cause and I couldn't find something similar.

listix
  • 3
  • 2

1 Answers1

0

my first thought is that your files have windows line endings (CRLF) as opposed to unix/linux line endings (LF), and that is messing with grep's ability to parse the file. try running this:

dos2unix temp1 temp2

then try your grep statement again.

extra note:

if you're going to make extensive use of cygwin, i strongly recommend you get yourself a better text editor that notepad or wordpad.

notepadd++ is one option that easily allows you to use windows or unix/linux line endings, among a myriad of other features.

nullrevolution
  • 3,937
  • 1
  • 18
  • 20
  • Thank you. This was driving me mad. Using the dos2unix it worked fine. Personally I use emacs for my editing needs, I think I will make a macro to change my files from now on. Thank you so much. – listix Dec 06 '12 at 21:22