3

In Unix, execute

diff -y file1 file2

can see two files side-by side. And execute

diff -c file1 file2

can see two files' difference with 3 line context. Execute

diff -y --supress-common-lines

can suppress all the common lines. But what if I want to display side-by-side but with 3 lines context? --supress-common-lines will provide no context at all

diff -y -c file1 file2

will give me conflicting output style options. Is there a way to achieve that?

Dmitrii2333
  • 323
  • 1
  • 5
  • 7
  • Note that --supress-common-lines might only be available on most modern diffutils versions. For instance, on diffutils 3.3 (On CentOS 7.7) it is not included. – Kiteloopdesign Mar 09 '21 at 17:46

1 Answers1

4

It seems that diff(1) doesn't allow it, but vimdiff seems to work:

vimdiff -c 'set diffopt=context:3' file1 file2

Downside is that it's interactive-only, you can't dump the diff to a file, but then again, side-by-side diffs are not very useful in files. However, if you do want to save it to a file, this awesome answer will have you do:

vimdiff -c 'set diffopt=context:3' -c TOhtml -c 'w! output.html' -c 'qa!' file1 file2

Not ideal, but it's something.

root
  • 5,528
  • 1
  • 7
  • 15