Hello,
I am looking for a script, or pointer to an approach to creating a script, that will compare two versions of a codebase and output a third directory structure containing only the files that differ between the two. I use diff quite often, but it will only create patch files (AFAIK). Does anyone have any suggestions?
Thanks,
Jim
You can use md5 or cksum to get a checksum for each file. Assuming you have identical filename, each directory has the same number of files in both directories and the directories are:
/path/to/source/dir1 and /path/to/source/dir2
try something like this (untested)
#!/bin/ksh
cd /path/to/source
mkdir ./both/dir1
mkdir ./both/dir2
cd .dir1
find . -type f | \
while read file1
do
cksum $file1 | read ck1 dummy dummy1
file2=../dir2/"$file"
cksum $file2 | read ck2 dummy dummy1
if [[ "$ck1" != "$ck2" ]] ; then
cp $file1 ../both/dir1/$file1
$( cd /path/to/source/dir2 ; cp $file1 ../both/dir2/$file1)
fi
done
Hi Jim,
Thanks alot! I didn't even think of checksumming... I'll give this a try. However, while the filenames will be identical, there may be differences in the number of files/directories between the two sources.
Jim
You'll have to deal with oddballs your own way. If dir1 had file13.c and dir2 did not have have file13.c, I would say that's a discrepency, so file13.c gets moved into the discrepency pile.
If there are different trees involved you will have to find a way to have both sets of trees under /both/dir1 & /both/dir2