How can I ignore line endings when comparing files?
DiffDiff Problem Overview
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?
Diff Solutions
Solution 1 - Diff
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.