Issue in comparing (cmp) two files

Hi All,

I have to compare set of files so I created a case statement with the option to give more than one file to compare. The Problem now i am facing is, if I compare the files directly, from prompt or just using the script only for a particular file then It's saying No difference, but If I try to use it with the script for more than file then It's showing some difference. I tried giving echo and other things but doesn't able find the clue.

Here is what I have written.

# Comparing only the data records alone
count=86
test='87|88|89|90|91|93'
while [ $count -lt 94 ]
do
count=`expr $count + 1`
eval "case $count in
$test)
sed '1d;$d' /appl/data/test/uit/FILE20${count}/FILE20${count}* > /appl/data/test/files/diff/FILE20${count}D;
sed '1d;$d' /appl/data/test/files/copydir/FILE00$count > /appl/data/test/files/diff/FILE20${count}M;
cmp /appl/data/test/files/diff/FILE20${count}D /appl/data/test/files/diff/FILE20${count}M > sed_diff_FILE00${count}D;
rm /appl/data/test/files/diff/FILE20${count}M;
rm /appl/data/test/files/diff/FILE20${count}D;
;;
*)
;;
esac"
done

I gave * because the file will be like FILE2087_M or FILE2087_D to represent the Monthly or daily file and I am sure only one file is available in the dir.

For the above code I am getting difference in all the file.
/appl/data/test/files/diff/FILE2087D /appl/data/test/files/diff/FILE2087M differ: char 32521, line 62
/appl/data/test/files/diff/FILE2088D /appl/data/test/files/diff/FILE2088M differ: char 3374, line 23
/appl/data/test/files/diff/FILE2089D /appl/data/test/files/diff/FILE2089M differ: char 6553, line 56
/appl/data/test/files/diff/FILE2090D /appl/data/test/files/diff/FILE2090M differ: char 29968, line 281
/appl/data/test/files/diff/FILE2091D /appl/data/test/files/diff/FILE2091M differ: char 26463, line 408

But If I run the command Like the below
sed '1d;$d' /appl/data/test/uit/FILE2087/FILE2087* > /appl/data/test/files/diff/FILE2087D
sed '1d;$d' /appl/data/test/files/copydir/FILE0087 > /appl/data/test/files/diff/FILE2087M
cmp /appl/data/test/files/diff/FILE2087D /appl/data/test/files/diff/FILE2087M

I am not getting any message that means both files are similar and there is no difference.

Help me if anybody knows/faced this issue earlier.

Thanks in Advance.

Are you sure that the eval statement required ?
Under bash and Ksh, the following script works fine :

test=XX
while read x
do
   case "$x" in
   $test) echo "[$test] found" ;;
       *) echo "[$test] not found"    ;;
   esac
done

try

# Comparing only the data records alone
count=86
test='87|88|89|90|91|93'
while [ $count -lt 94 ]
do
   count=`expr $count + 1`
   case "$count" in
      $test) 
         sed '1d;$d' /appl/data/test/uit/FILE20${count}/FILE20${count}* > /appl/data/test/files/diff/FILE20${count}D;
         sed '1d;$d' /appl/data/test/files/copydir/FILE00$count > /appl/data/test/files/diff/FILE20${count}M;
         cmp /appl/data/test/files/diff/FILE20${count} D /appl/data/test/files/diff/FILE20${count}M > sed_diff_FILE00${count}D; 
         rm /appl/data/test/files/diff/FILE20${count}M;
         rm /appl/data/test/files/diff/FILE20${count}D; 
         ;;
      *) 
         ;;
   esac
done

Jean-Pierre.

Hi Jean,
Thanks for your effort. I am using Ksh. The first example you provided works fine. But the Issue here is more than one value. If I run script with out eval then it's not matching the value with the case statement. I got this idea of using eval from on the Thread here, but unfortunately I am not able to find that exact thread to post here. I already tried the second script before trying the eval, as it goes to *) option always.

Do you think eval command is making the issue here?

Thanks once again.

You're right! eval is required.

I think that your problem comes from the sed statements.
The $ character must be escaped.

sed '1d;\$d' /appl/data/test/uit

Jean-Pierre.

It worked fine. Thanks for your help Jean.