wdiff to highlight differences

364 Views Asked by At

How do I use wdiff to show the word differences between two files? Right now, I can show which words are in common between two files and print out the stats. I'd like to color red exactly which words are different.

#! usr/bin/bash
wdiff -si12 exp3.txt out.txt | colordiff

This outputs:

Input an integer greater than or equal to 0 or -1 to quit: 
The largest number is 5
Goodbye!
exp3.txt: 6 words  39 100% common  0 0% deleted  0 0% changed
out.txt: 6 words  39 100% common  0 0% inserted  0 0% changed

It prints all the common words. I've done --help to look at the supported wdiff commands but I couldn't find how to highlight differences. Any help is appreciated!

1

There are 1 best solutions below

2
Erwin On

The final example on the wdiff manual page suggests a way to add color to the word diffs:

$ cat file1
Hello world, how are you today?
$ cat file2
Hello universe, how are you today?
$ wdiff -n -w $'\033[30;41m' -x $'\033[0m' -y $'\033[30;42m' -z $'\033[0m'  file1 file2