showing differences within a line in diff output
Asked Answered
Z

7

26

This StackOverflow answer has an image of KDiff3 highlighting intra-line differences. Does someone know of a tool which can show the same (ex, via color) on the command line?

Another way to think of this is wanting to diff each difference in a patch file.

Zounds answered 27/8, 2009 at 16:34 Comment(4)
Try this perl script from the git project. This blog describes it. See my gist to see how I set it up (pager section)Phototherapy
unix.stackexchange.com/questions/11128/diff-within-a-lineSporty
Ciro: Yup, including my answer: use emacs' ediff mode...Lyingin
Does this answer your question? Using 'diff' (or anything else) to get character-level diff between text filesNarvaez
S
17

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.

Secluded answered 27/8, 2009 at 16:50 Comment(0)
L
12

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

Lanner answered 16/6, 2016 at 14:42 Comment(0)
R
5

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).

Rakehell answered 13/3, 2012 at 15:7 Comment(1)
This is the only vim-less solution that worked for me.Frater
N
4

ccdiff is a convenient dedicated tool for the task. Here is what an example may look like with it:

ccdiff example output

By default, it highlights the differences in color, but it can be used on a console without color support too.

The package is included in the main repository of Debian:

ccdiff is a colored diff that also colors inside changed lines.

All command-line tools that show the difference between two files fall short in showing minor changes visuably useful. ccdiff tries to give the look and feel of diff --color or colordiff, but extending the display of colored output from colored deleted and added lines to colors for deleted and addedd characters within the changed lines.

Narvaez answered 14/11, 2020 at 6:43 Comment(0)
K
3

I had a similar problem and wanted to avoid using vimdiff. I found dwdiff (which is available in Debian) to have several advantages over wdiff.

The most useful feature of dwdiff is that you can customise the delimiters with -d [CHARS], so it's useful for comparing all kinds of output. It also has color built in with the -c flag.

Kenji answered 8/5, 2014 at 9:32 Comment(0)
D
2

You might be able to use colordiff for this.

In their man page:

Any options passed to colordiff are passed through to diff except for the colordiff-specific option 'difftype', e.g.

colordiff --difftype=debdiff file1 file2

Valid values for 'difftype' are: diff, diffc, diffu, diffy, wdiff, debdiff; these correspond to plain diffs, context diffs, unified diffs, side-by-side diffs, wdiff output and debdiff output respectively. Use these overrides when colordiff is not able to determine the diff-type automatically.

I haven't tested it, but the side-by-side output (as produced by diff -y file1 file2) might give you the equivalent of in-line differences.

Disaccord answered 27/8, 2009 at 16:59 Comment(1)
You can also pipe diff output into colordiff, but I confirm that it doesn't workPaludal
S
0

icdiff is another option. It can be used standalone, or as a Git command (git icdiff).

Example

Siphonophore answered 4/6 at 15:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.