How can I ignore line endings when comparing files?

Diff

Diff 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.

Categories

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionvikingsteveView Question on Stackoverflow
Solution 1 - DiffRuslan OsmanovView Answer on Stackoverflow