I am comparing two text files and I get the following result:
diff file1 file2 | grep 12345678 > 12345678 < 12345678
As you can see, the same string exists in both files, and both files were sorted with sort
.
The line endings must be getting in the way here (Windows vs. Unix).
Is there a way to get diff
to ignore line endings on Unix?
CR = Carriage Return ( \r , 0x0D in hexadecimal, 13 in decimal) — moves the cursor to the beginning of the line without advancing to the next line. LF = Line Feed ( \n , 0x0A in hexadecimal, 10 in decimal) — moves the cursor down to the next line without returning to the beginning of the line.
vi shows newlines (LF character, code x0A ) by showing the subsequent text on the next line. Use the -b switch for binary mode. For example , vi -b filename or vim -b filename -- . It will then show CR characters ( x0D ), which are not normally used in Unix style files, as the characters ^M .
^M represents carriage return. This diff means something removed a Unicode BOM from the beginning of the line and added a CR at the end.
Use the --strip-trailing-cr
option:
diff --strip-trailing-cr file1 file2
The option causes diff
to strip the trailing carriage return character before comparing the files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With