Search code examples
bashcomparediffline-breaks

can the 'diff' command ignore different kinds of line breaks?


I want to check the similarity of two .txt documents that were created on different operating systems (Windows and OSX). Going with the 'diff' command outputs differences for every single line of the document although many of them "look" identical.

I remember there was a difference between line breaks that are used on Windows and Unix based systems and I assumed, that's what's causing a trouble.

Is there an option for the diff command to ignore this difference? I found "-w" on the man page which ignores all white spaces, but that's not really what I want.


Solution

  • diff --strip-trailing-cr file1 file2
    

    or

    diff <(dos2unix < file_from_windows) file_from_osx
    

    or

    diff <(tr -d '\r' < file_from_windows) file_from_osx