Show only right side of --side-by-side diff

Solution 1:

What you seem to want is not a side-by-side diff at all - but rather one in which you customize the format to exclude lines from either the old or the new file completely. For example, given

$ cat file1v1
  2 Africa
  3 America
  3 Asia
  4 Antarctica
  4 Oceania
  7 Europe
$ cat file2v1
  3 Africa
  3 America
  3 Asia
  4 Antarctica
  4 Oceania
  7 Europe

Then

$ diff --new-line-format='| %L' --unchanged-line-format='  %L' --old-line-format= file1v1 file2v1
|   3 Africa
    3 America
    3 Asia
    4 Antarctica
    4 Oceania
    7 Europe

while given

$ cat file1v2
  3 Africa
  3 America
  3 Asia
  4 Antarctica
  4 Oceania
  8 Europe

$ cat file2v2
  3 Africa
  3 America
  4 Antarctica
  4 Asia
  4 Oceania
  8 Europe

then

$ diff --new-line-format='> %L' --unchanged-line-format='  %L' --old-line-format= file1v2 file2v2
    3 Africa
    3 America
    4 Antarctica
>   4 Asia
    4 Oceania
    8 Europe

Solution 2:

This is actually the RIGHT column, though it ends up on the left. Also, it's a very ugly solution and I'm sure some smarter folks will do better. But here is is anyway:

$ diff --side-by-side file1 file2 | sed -r 's/[^\t]*\t*(.*)/\1/' | sed -r 's/^ *(\||>|<)\t /\1/'

| 3 Africa
  3 America
  3 Asia
  4 Antarctica
  4 Oceania
  7 Europe

Explanation

  • -r use ERE
  • s/old/new/ replace old with `new
  • [^\t]* anything but tabs, please
  • \t* as many tabs as you like
  • (.*) any number of any characters on the line, (saved) for later
  • \1 the pattern we saved
  • s/^ *(\||>|<)\t /\1/ get rid of the stuff around the | or > or < character on lines that differ to fix the alignment