Skip to main content
2 of 6
added 83 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 Ь c d e f g h i j k l m n o p q r s t u v w x y z

I want the output to be something like:

[-b-]{+Ь+}

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

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

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