Search code examples
linuxtextdiffgnueol

Side-by-side diff (-y) : how to hide the reverse-video ^M (at end-of-line)?


Problem

I'm diffing files side-by-side (-y) on a GNU/Linux system:

$ diff -y file1 file2

but each end-of-line results in spurious ^M in reverse video... one for the left line and one for the right line.

Here's the version of diff I'm using:

diff (GNU diffutils) 3.3

EDIT: I forgot to mention I'm combining diff with less, and without | less the ^M are not shown:

$ diff -y file1 file2 | less

Question

How can one avoid these reverse-video ^M chars to be produced by diff?


Note1: Without the -y I don't have the problem. But I need this argument.

Note2: I can't do unix2dos or dos2unix on any of the files because I must use them read-only.

Note3: I have found similar questions that correspond to using diff with GIT, they didn't seem to be helpful in my case - I'm not using GIT here, just diff.


Solution

  • Try diff -y --strip-trailing-cr file1 file2.