cdiff - compare and/or merge two text files
B<cdiff> [B<-skipto> I<pattern>] [B<-merge[1|2]>|B<-trim>] F<file1> F<file2>
cdiff will compare two text files, ignoring differences in layout, and produce an output file which shows the differences. It can also be used to merge the two files into a single version, choosing between variant readings in the files based on a dictionary of words. (See the -merge option below).
The layout of the output is taken from file2.
Characters deleted from file1 are shown in [angle brackets], while inserted characters are shown in {curly brackets}.
Suppose file1 contains the following text:
CHAPTER I
Call me Ishmael. Some years ago--never mind how long precisely-- having little or no money in my purse and nothing particular to interest me on shore,I thought I would sail about a little and see the watery port of the wor1d. It is a way I have of driving of the spleen, and regulating the circulation.
while file2 contains this:
Chapter 1
Call me ishmael. Some years ago- never mind how long precisely- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little see the vatery part of the world. It is a way I have of driving off the spleen and regulating the circulation.
The result of cdiff file1 file2
is:
C[HAPTER I]{hapter 1}
Call me [I]{i}shmael. Some years ago-[-]{ }never mind how long precisely-[-] having little or no money in my purse{,} and nothing particular to interest me on shore, I thought I would sail about a little [and] see the [w]{v}atery part of the wor[1]{l}d. It is a way I ha[s]{ve} of driving of{f} the spleen[,] and regulating the circulation.
Adding the -trim
option shows only the lines with differences,
which are within 50 lines of a chapter heading (this is designed
for Project Gutenberg's legal team):
1:C[HAPTER I]{hapter 1} 3: Call me [I]{i}shmael. Some years ago-[-]{ }never mind how long 4: precisely-[-] having little or no money in my purse{,} and 6: I would sail about a little [and] see 7: the [w]{v}atery part of the wor[1]{l}d. 8: It is a way I ha[s]{ve} of driving of{f} the 9: spleen[,] and regulating the circulation.
The -merge option merges the files by taking the ``obvious'' choice where possible, but leaving the choices in otherwise. The ``obvious'' choices are:
The result of cdiff -merge file1 file2
is:
CHAPTER I
Call me Ishmael. Some years ago- never mind how long precisely-- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I [has]{have} of driving [of]{off} the spleen and regulating the circulation.
Note that there are only two variants left, and these are expanded to whole words: [has]{have} and [of]{off}.
If you want to see which choices are made automatically, do
cdiff -merge2 file1 file2 > file3
and then compare file3 against file2, perhaps with:
cdiff file2 file3
cdiff takes the following options:
cdiff requires perl and wdiff to be available. wdiff also requires the diff utility.
Martin Ward, <martin@gkc.org.uk>.
wdiff, diff
This program is distributed under the Artistic License.