wdiff
is actually a very old method of comparing files word-by-word. It worked by reformatting files, then using diff
to find differences and passing it back again. I myself suggested adding context, so that rather than word-by-word compare, it does it with each word surrounded by other 'context' words. That allows the diff to synchronise itself on common passages in files much better, especially when files are mostly different with only a few blocks of common words. For example when comparing text for for plagiarism, or re-use.
dwdiff
was later created from wdiff
. But dwdiff
uses that text reformatting function to good effect in dwfilter
. This is a great development – it means you can reformat one text to match another, and then compare them using any line-by-line graphical diff displayer. For example, using it with "diffuse" graphical diff....
dwfilter file1 file2 diffuse -w
This reformats file1
to the format of file2
and gives that to diffuse
for a visual comparison. file2
is unmodified, so you can edit and merge word differences into it directly in diffuse
. If you want to edit file1
, you can add -r
to reverse which file is reformatted. Try it and you will find it is extremely powerful!
My preference for the graphical diff (shown above) is diffuse
as it feels far cleaner and more useful. Also it is a standalone python program, which means it is easy to install and distribute to other UNIX systems.
(ASIDE: newer version of diffuse have refactored the code into a huge array of files. I kept a copy of the old single-file version of diffuse to use on systems without diffuse installed)
Other graphical diffs seem to have a lot of dependencies, but can also be used (your choice). These include meld
, kdiff3
or xxdiff
.
git diff --word-diff --word-diff-regex=. f1 f2
works like a charm