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)
Code:
#!/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