File Comparision by using Shell Script

Hello All,

I am trying to find 2 file comparision by using Shell Script. For example, I am having 2 directories namely DAY1 & DAY2. DAY1 directory contains file1.dat, file2.dat, file3.dat, file4.dat, file5.dat & DAY2 directory contains file1.dat, file2.dat, file3.dat, file4.dat, file5.dat. Now, want to compare DAY2/file1.dat with DAY1/file1.dat and store the result in tmp file, .... DAY2/file5.dat with DAY1/file5.dat and store the result in tmp file like. I.e., DAY2/file1.dat first row checkes with each rows in DAY1/file1.dat and so on. How to do in Shell Script. File row length is dynamic and this shell script is to run interactively by using batch jobs in UNIX. Does anybody use this requirement in your project or suggest me how to do this approach. In fact, I am new to UNIX shell scripting.

Regreat your suggestions/help.

Regards
Venkat.

#!/usr/bin/ksh

DIR1=$PATH'/DAY1'
DIR2=$PATH'/DAY2'

for i in `ls -1 $DIR1`
do
#check if same file exists in DIR2 also
filename=`basename $i`
FILE1=$i
FILE2='DIR2/'$filename
diff FILE1 FILE2 > tmp_FILE1_FILE2
done

Modify the peice of code to suit your needs.

Rishi

Hello,

Is there any otherway to find without using DIFF statement?

Regards,
Venkat

you can use "cmp" if diff is not to your taste :wink: