showing differences within a line in diff output

喜夏-厌秋 提交于 2019-12-03 01:41:45
ire_and_curses

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.

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:

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

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!