showing differences within a line in diff output

I don't know if this is sufficiently command line for your purpose, but vimdiff can do this (even does colour). See for example the image in this related question.


Another intuitive way to see all word-sized differences (though not side-by-side) is to use wdiff together with colordiff (you might need to install both). An example of this would be:

wdiff -n {file-A} {file-A} | colordiff

You can optionally pipe this into less -R to scroll through the output (-R is used to show the colors in less).


I tried all the tools I found: wdiff, dwdiff, kdiff3, vimdiff to show the difference between two long and slightly different lines. My favourite is diff-highlight (part of git contrib)

  • it supports diff format - great advantage over tools requiring two files like (dwdiff), e.g. if you need to visualize the output of unit tests
  • it highlights with black+white or with color if you connect it to colordiff
  • highlights characterwise - helpful for comparing long lines without spaces (better than wdiff)

Installation

On Ubuntu, you probably already have it as part of git contrib (installed within the git deb package). Copy or link it into your ~/bin folder from /usr/share/doc/git/contrib/diff-highlight/diff-highlight

Usage example

cat tmp.diff | diff-highlight | colordiff

Result:

enter image description here