Skip to main content
4 of 6
deleted 42 characters in body
anol
  • 835
  • 1
  • 10
  • 19

diff showing only differences inside line

I want to compare lines in two files, but to minimize noise in the output, I want only the actual differences in the lines to be printed.

For instance, given the two files below:

a.txt

a b c d e f g h i j k l m n o p q r s t u v w x y z

b.txt

a B c d e f g h i j k l m n o p q r s t u v w x y z

(the difference between them is the case of letter b)

I want the output to be something like:

[-b-]{+B+}

Currently, the best approach I found was to use git diff --word-diff, but it outputs the whole line:

a [-b-]{+B+} c d e f g h i j k l m n o p q r s t u v w x y z

Is there a more direct way to do it, other than manually parsing the output? Also, ideally I would prefer to use something more commonly available than git diff, e.g. a POSIX shell tool that would not require the user to install extra packages.

anol
  • 835
  • 1
  • 10
  • 19