### 2.2 Actual examples of `wdiff` usage ¶

This section presents a few examples of usage, most of them have been contributed by `wdiff` users.

- Change bars example.
  - This example comes from a discussion with Joe Wells.

    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.

    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.

    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 or 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 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'

- Colored output example.
  - This example comes from Martin von Gagern.

    If you like colored output, and your terminal supports ANSI escape sequences, you can use this invocation:

        wdiff -n \
          -w $'\033[30;41m' -x $'\033[0m' \
          -y $'\033[30;42m' -z $'\033[0m' \
          ... | less -R

    This will print deleted text black on red, and inserted text black on green, assuming that your normal terminal colors are white on black. Of course you can choose different colors if you prefer.

    The ‘`$'…'`’ notation is supported by GNU bash, and maybe other shells as well. If your shell doesn’t support it, you might need some more tricks to generate these escape sequences as command line arguments.

On a related note, GNU Emacs users might notice that the interactive function `compare-windows` ignores changes in whitespace, if it is given a numeric argument. If the variable `compare-ignore-case` is non-`nil`, it ignores differences in case as well. So, in a way, this offers a kind of incremental version of `wdiff`.