I have a file with near-identical lines which have some slight differences, and I want to have a highlight of the differences between each line.
- The quick brown fox jumps over the lazy dog.
- The quack brown fox leaps over the lazy dog.
- The quack fox leaps over the very lazy dog.
- The quack fox leaps oer the really very lazy dog.
(here bold text marks characters that have been inserted and changed compared to the previous line, and italics marks characters that are removed in the next line).
The highlighting doesn't need to look exactly like in the example, but it should indicate which characters have been added, changed or removed. And it should indicate this solely with highlighting (ie. no printing of old and new characters in one line), so that the actual text on each line is still identical to the original text.
I have tried to build something with
dwdiff (iterating over the lines and then comparing consecutive lines), but haven't found a way to highlight deleted characters:
infile=$1 line1= line2= lineNo=0 while IFS="" read -r nextLine || [ -n "$nextLine" ]; do line1=$line2 line2=$nextLine if [[ "$lineNo" -gt 0 ]]; then dwdiff -1 -c <(printf '%s\n' "$line1") <(printf '%s\n' "$line2") else printf '%s\n' "$line2" fi lineNo=$((lineNo+1)) done
Ideally the diff would actually work on characters, but word-level differences would be OK as well.
Is there a way to get this result with
dwdiff? Or is there an existing tool which does this?