wdiffwdiff is a front-end to GNU diff. It compares two files,
finding which words have been deleted or added to the first in order to
create the second. It has many output formats and interacts well with
terminals and pagers (notably with less). wdiff is
particularily useful when two texts differ only by a few words and
paragraphs have been refilled.
This is release 0.5.
The program wdiff is a front end to diff for comparing
files on a word per word basis. A word is anything between whitespace.
This is useful for comparing two texts in which a few words have been
changed and for which paragraphs have been refilled. It works by
creating two temporary files, one word per line, and then executes
diff on these files. It collects the diff output and uses
it to produce a nicer display of word differences between the original
files.
Ideally, wdiff should avoid calling diff and do all the
work internally, allowing it to be faster and more polished. However, I
loathe replicating the diff algorithm and development effort,
instead of improving diff itself. It would be more sensible to
integrate wdiff into diff than the other way around. I
did it this way only because I had a sudden and urgent need for it, and
it would have taken too much time to integrate it correctly into GNU
diff. Your advice or opinions about this are welcome.
wdiff was written by {No value for `Francois'} Pinard. Please report
bugs to bug-gnu-utils@prep.ai.mit.edu. Include the version
number, which you can find by running `wdiff --version'.
Include in your message sufficient input to reproduce the problem
and also, the output you expected.
wdiffThe format for running the wdiff program is:
wdiff option ... old_file new_file
wdiff compares files old_file and new_file and
produces an annotated copy of new_file on standard output. The
empty string or the string `-' denotes standard input, but standard
input cannot be used twice in the same invocation. The complete path of
a file should be given, a directory name is not accepted. wdiff
will exit with a status of 0 if no differences were found, a status of 1
if any differences were found, or a status of 2 for any error.
In this documentation, deleted text refers to text in old_file which is not in new_file, while inserted text refers to text on new_file which is not in old_file.
wdiff supports the following command line options:
wdiff on the standard error output.
wdiff are now put under the control of this option.
By using it, a pager is interposed whenever the wdiff output is
directed to the user's terminal. Without this option, no pager will be
called, the user is then responsible for explicitly piping wdiff
output into a pager, if required.
The pager is selected by the value of the PAGER environment
variable when wdiff is run. If PAGER is not defined at
run time, then a default pager, selected at installation time, will be
used instead. A defined but empty value of PAGER means no pager
at all.
When a pager is interposed through the use of this option, one of the options `-l' or `-t' is also selected, depending on whether the string `less' appears in the pager's name or not.
It is often useful to define `wdiff' as an alias for `wdiff
-a'. However, this hides the normal wdiff behaviour. The
default behaviour may be restored simply by piping the output from
wdiff through cat. This dissociates the output from the
user's terminal.
-p, but also over-strikes whitespace associated with
inserted text. less shows such whitespace using reverse video.
This option is not selected by default. However, it is automatically
turned on whenever wdiff launches the pager less. See
option `-a'.
This option is commonly used in conjunction with less:
wdiff -l old_file new_file | less
termcap strings for emphasising parts of
output, even if the standard output is not associated with a terminal.
The `TERM' environment variable must contain the name of a valid
termcap entry. If the terminal description permits, underlining
is used for marking deleted text, while bold or reverse video is used
for marking inserted text. This option is not selected by default.
However, it is automatically turned on whenever wdiff launches a
pager, and it is known that the pager is not less. See
option `-a'.
This option is commonly used when wdiff output is not redirected,
but sent directly to the user terminal, as in:
wdiff -t old_file new_file
A common kludge uses wdiff together with the pager more,
as in:
wdiff -t old_file new_file | more
However, some versions of more use termcap emphasis for
their own purposes, so strange interactions are possible.
Note that options `-p', `-t', and `-[wxyz]' are not mutually exclusive. If you use a combination of them, you will merely accumulate the effect of each. Option `-l' is a variant of option `-p'.
wdiff usageThis section presents a few examples of usage, most of them have been
contributed by wdiff users.
This example comes from a discussion with Joe Wells, `jbw@cs.bu.edu'.
The following command produces a copy of new_file, shifted right one space to accommodate change bars since the last revision, ignoring those changes coming only from paragraph refilling. Any line with new or changed text will get a `|' in column 1. However, deleted text is not shown nor marked.
wdiff -1n old_file new_file |
sed -e 's/^/ /;/{+/s/^ /|/;s/{+//g;s/+}//g'
Here is how it works. Word differences are found, paying attention only
to additions, as requested by option `-1'. For bigger changes
which span line boundaries, the insert bracket strings are repeated on
each output line, as requested by option `-n'. This output is then
reformatted with a sed script which shifts the text right two
columns, turns the initial space into a bar only if there is some new
text on that line, then removes all insert bracket strings.
LaTeX example.
This example has been provided by Steve Fisk, `fisk@polar.bowdoin.edu'.
The following uses LaTeX to put deleted text in boxes, and new text in double boxes:
wdiff -w "\fbox{" -x "}" -y "\fbox{\fbox{" -z "}}" ...
works nicely.
troff example.
This example comes from Paul Fox, `pgf@cayman.com'.
Using wdiff, with some troff-specific delimiters gives
much better output. The delimiters I used:
wdiff -w'\s-5' -x'\s0' -y'\fB' -z'\fP' ...
This makes the pointsize of deletions 5 points smaller than normal, and emboldens insertions. Fantastic!
I experimented with:
wdiff -w'\fI' -x'\fP' -y'\fB' -z'\fP'
since that's more like the defaults you use for terminals/printers, but since I actually use italics for emphasis in my documents, I thought the point size thing was clearer.
I tried it on code, and it works surprisingly well there, too...
Marty Leisner `leisner@eso.mc.xerox.com' says:
In the previous example, you had smaller text being taken out and bold face inserted. I had smaller text being taken out and larger text being inserted, I'm using bold face for other things, so this is more clear.
wdiff -w '\s-3' -x'\s0' -y'\s+3' -z'\s0'