Issue in comparing (cmp) two files


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
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.
# 2  
Are you sure that the eval statement required ?
Under bash and Ksh, the following script works fine :
Code:
test=XX
while read x
do
   case "$x" in
   $test) echo "[$test] found" ;;
       *) echo "[$test] not found"    ;;
   esac
done

try
Code:
# 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.
# 3  
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.
# 4  
You're right! eval is required.

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

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

Jean-Pierre.
# 5  
It worked fine. Thanks for your help Jean.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #295
Difficulty: Easy
Ubuntu releases updated versions predictably every 3 months.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing two files issue.

more prod.properties # remote connection details cdr_url=http://myprod.col.net:1890/service cdr_user=user1 cdr_pswd=pass11 boot_time=ON more back.properties cdr_url=http://myback.col.net:1890/service cdr_user=user1 cdr_pswd=pass11 storage=file I need to compare the back.properties... (6 Replies)
Discussion started by: mohtashims
6 Replies

2. UNIX for Dummies Questions & Answers

Comparing two files issue

Hi all, I need your help fixing an issue with this code. I am a newbie to UNIX programming and there is an issue with this code I am hoping you can help me correct. I have two files (system_files with 8342 records and rules1.txt file with 762 records). My understanding from the script below, is... (2 Replies)
Discussion started by: Mustafa19804
2 Replies

3. Shell Programming and Scripting

awk script issue : comparing two files with a pattern

File 1 ################################################################# pma.zcal.iop_pma_zcal_cntl (2710.080 115.200) pma.lanea23.rx0.cntl (696.960 844.800) pma.lanea67.rx0.cntl (1733.760 844.800) pma.zcal.iop_pma_zcal_cust (2280.960 115.200)... (1 Reply)
Discussion started by: jaita
1 Replies

4. Shell Programming and Scripting

How to compare files in two folders using cmp?

i recently copied 400GB of data from a NTFS drive to a ext4 drive. I want to verify that the data is 100% identical to the original. I wanted to use cmp but it only does two files. The directory that was copied contains many subdirectories and all sorts of files (not just text). So I guess... (5 Replies)
Discussion started by: fuzzylogic25
5 Replies

5. Solaris

cmp file

Dear all, for i in <List of Filename> FILENAME=`echo $i` do cp -p $FILENAME /temp /bin/cmp $FILENAME /temp/$FILENAME done I am planning to do something like this on a daily basis, so i want to ask that, if the comparison on the files encounter error, ... (2 Replies)
Discussion started by: beginningDBA
2 Replies

6. Shell Programming and Scripting

date cmp

Please don't count this as a similar post.....I got the ftp part working....I am stuck how to find the files between two dates. I have 5 files filename.20090505.txt filename.20090504.txt filename.20090503.txt filename.20090502.txt filename.20090501.txt My load date is 20090501 and run date... (5 Replies)
Discussion started by: RubinPat
5 Replies

7. Shell Programming and Scripting

CMP two files with slight difference and return code

I am comparing two files which are identical except for the timestamp which is incorporated within the otherwise same 372 bytes. I am using the command: cmp -s $Todays_file $Yesterdays_file -i 372 When I run the command without the -i 372 it shows the difference i.e. the timestamp.... (5 Replies)
Discussion started by: gugs
5 Replies

8. UNIX for Dummies Questions & Answers

cmp 2 variables

Hi I have two variables contining a set of near identical lines, i'd like to list the lines that differ? Prefereably i'd like not to save the variables into a file first. i.e var1 tag:val1 tag:val2 tag:val3 var2 tag:val1 tag:val4 tag:val3 i'd like the result to print out... (2 Replies)
Discussion started by: nickrick
2 Replies

9. Shell Programming and Scripting

cmp, diff need options

Hi, I am using diff filename1 filename2, as these files are of huge size,I want to know the count(n) no. of different records to be displayed on the terminal. I do not want the contents of file i mean different lines to be displayed. Cheers Kunal. (0 Replies)
Discussion started by: niceboykunal123
0 Replies

Featured Tech Videos