wdiff
Show word-by-word differences between two files
TLDR
Compare two files
Ignore case when comparing
Display how many words are deleted, inserted or replaced
SYNOPSIS
wdiff [OPTION]... FILE1 FILE2
PARAMETERS
-w chars, --word-separators=chars
Specifies characters that delimit words. By default, includes spaces, tabs, and newlines.
-i, --ignore-case
Ignores differences in case when comparing words.
-x chars, --ignore-boundary-chars=chars
Ignores specified characters if they appear at the beginning or end of a word.
-y chars, --ignore-all-chars=chars
Ignores specified characters anywhere within words or between words.
-t, --terminal
Forces colored and underlined output, even if standard output is not a terminal.
--auto-terminal
Attempts to guess if output should be colored/underlined based on whether stdout is a TTY.
-p, --page
Paginates output through 'less' or the defined PAGER environment variable.
-s, --no-deleted
Suppresses the display of words deleted from the first file.
-n, --no-inserted
Suppresses the display of words inserted into the second file.
--diff-program=PROG
Specifies an alternative 'diff' program (e.g., 'diff -u') to use for comparison instead of the default.
--avoid-wraps
Attempts to format output to avoid line wrapping, especially with long lines.
--statistics
Outputs statistics about the changes, such as the number of words changed, added, or deleted.
DESCRIPTION
wdiff is a powerful utility designed to compare two files at the word level, offering a more granular difference analysis than the traditional diff command. Instead of comparing line by line, wdiff identifies and highlights specific words that have been changed, added, or deleted between the two input files.
It achieves this by transforming the input files into a format where each word resides on its own line, then leveraging a standard diff program to find the line-based differences, and finally translating these differences back to the original word context. The output typically presents deleted words enclosed in [-...-] and inserted words in {+...+}, or using colors and underlining for terminal display. This word-centric comparison is particularly useful for text documents, source code, or prose where minor edits within lines are common and a full line difference might be too broad.
CAVEATS
wdiff is essentially a wrapper script around the standard diff utility, which means its performance and capabilities are inherently tied to the underlying diff program. It creates temporary files internally, which can be an overhead for extremely large files. Its definition of a "word" might not always align with specific linguistic or programming contexts, requiring careful use of the --word-separators option. While it attempts to handle various character encodings, complex multi-byte character sets might sometimes lead to unexpected results.
EXIT STATUS
wdiff typically returns an exit status of 0 if no differences were found, 1 if differences were found, and 2 if an error occurred. This behavior mirrors that of the underlying diff utility.
CUSTOMIZING OUTPUT
wdiff allows extensive customization of its output format using options like --old-line-format, --new-line-format, and --unchanged-line-format. These options let users define how deleted, inserted, and unchanged words are displayed, often using escape sequences for colors and other text attributes, providing a highly flexible visual output.
HISTORY
wdiff has been a part of the GNU utilities for a long time, evolving as a specialized tool for textual comparison. Its implementation as a front-end script leveraging diff allows it to benefit from the robustness and efficiency of diff while providing a more granular word-level analysis. It fills a niche for users who need to identify subtle changes within lines, which diff alone cannot provide without additional post-processing. Its development has focused on enhancing output clarity and providing flexible word definition options.