0

I have two sorted files and each only has one column. the first 45 lines in both of them are a bunch of numbers and they are the same between file1 and file2. when I used the diff command it returns these identical lines which is exactly the opposite of what I wanted. I wanted to find the differences, does anyone have any suggestions why this is happening? the rest of the lines in these two files start with two letters and then followed by a number of digits. the result of diff command:

1,45c1,45
< 1012
< 1051
< 1054
< 1107
< 115
< 1158
< 1242
< 1294
< 1388
< 1442
< 1607
< 1608
< 1650
< 1665
< 1732
< 1756
< 2045
< 2046
< 2059
< 2147
< 2219
< 2244
< 2272
< 2302
< 2355
< 2374
< 2376
< 2380
< 2434
< 2496
< 2612
< 2773
< 2864
< 295
< 2992
< 3061
< 3102
< 3222
< 3233
< 384
< 395
< 451
< 705
< 860
< 963
---
> 1012
> 1051
> 1054
> 1107
> 115
> 1158
> 1242
> 1294
> 1388
> 1442
> 1607
> 1608
> 1650
> 1665
> 1732
> 1756
> 2045
> 2046
> 2059
> 2147
> 2219
> 2244
> 2272
> 2302
> 2355
> 2374
> 2376
> 2380
> 2434
> 2496
> 2612
> 2773
> 2864
> 295
> 2992
> 3061
> 3102
> 3222
> 3233
> 384
> 395
> 451
> 705
> 860
> 963
0

1 Answer 1

3

A possible explanation is that one of the files (but not the other) has DOS/Windows style line endings (CRLF instead of plain LF). Ex. given

$ printf '%d\n' {1..5} > file1
$ printf '%d\r\n' {1..5} > file2

then

$ diff file1 file2
1,5c1,5
< 1
< 2
< 3
< 4
< 5
---
> 1
> 2
> 3
> 4
> 5

If that is the issue, then you can use diff -w

   -w, --ignore-all-space
          ignore all white space

(which includes the carriage return character):

$ diff -ws file1 file2
Files file1 and file2 are identical
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .