I don't seem to find a way around this. Is there a one-liner to get only the right side of a diff --side-by-side
output?
For example:
For this: diff --side-by-side file1 file2
I get either of this two types of results:
2 Africa | 3 Africa
3 America 3 America
3 Asia 3 Asia
4 Antarctica 4 Antarctica
4 Oceania 4 Oceania
7 Europe 7 Europe
or
3 Africa 3 Africa
3 America 3 America
3 Asia <
4 Antarctica 4 Antarctica
> 4 Asia
4 Oceania 4 Oceania
8 Europe 8 Europe
How can I turn those into this:
| 3 Africa
3 America
3 Asia
4 Antarctica
4 Oceania
7 Europe
And this respectively:
3 Africa
3 America
4 Antarctica
> 4 Asia
4 Oceania
8 Europe
Note that I edited the original output of diff
so that it appears justified in this question. They appear aligned (column-wise) in the terminal but I had to adjust them a little bit here so they appear exactly as they appear in the terminal (columns neatly aligned), but you can replicate the output creating this input files:
File1 version 1
2 Africa
3 America
3 Asia
4 Antarctica
4 Oceania
7 Europe
File2 version 1
3 Africa
3 America
3 Asia
4 Antarctica
4 Oceania
7 Europe
File1 version 2
3 Africa
3 America
3 Asia
4 Antarctica
4 Oceania
8 Europe
File2 version 2
3 Africa
3 America
4 Antarctica
4 Asia
4 Oceania
8 Europe
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
Then
while given
then
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:
Explanation
-r
use EREs/old/new/
replaceold
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 saveds/^ *(\||>|<)\t /\1/
get rid of the stuff around the|
or>
or<
character on lines that differ to fix the alignment