The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
FTP Return Code wilsonSurya UNIX for Dummies Questions & Answers 1 10-06-2008 08:27 AM
to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's manas6 UNIX for Dummies Questions & Answers 0 06-05-2008 07:44 AM
asking about return code naamas03 Shell Programming and Scripting 3 08-28-2007 05:53 AM
return code of a process filedeliver High Level Programming 1 04-19-2007 02:42 AM
Return Code of tar in AIX dupeng AIX 3 02-23-2004 12:05 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-08-2008
gugs gugs is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 44
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. However, with -i 372 it works as expected displays no differences as it ignores the first 372 bytes.

However, in both cases the return code is set to 1. I was hoping that in the second case the return code would be set to 0 i.e. no changes as we are ignoring the first 372 bytes.

I do some further processing based on the return code. Is there a way I can compare the two files?
  #2 (permalink)  
Old 10-08-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,889
My "POSIX" compliant cmp doesn't contain this "-i" options. It sounds cool, but it doesn't have it. I also don't know what cmp would print out the timestamp difference.

So how about running each file through a process that strips the first 372 bytes, then compare the resulting files?

Code:
dd if=file1 bs=1 skip=372 of=file1.372 >/dev/null
dd if=file2 bs=1 skip=372 of=file2.372 >/dev/null
cmp -l file[12].372
rm -f file[12].372

  #3 (permalink)  
Old 10-08-2008
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 712
Hi.

The GNU cmp seems to work for me:

Code:
#!/bin/bash -

# @(#) s1       Demonstrate cmp, skipping initial bytes.

echo
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1) cmp
set -o nounset
echo

FILE1=data1
FILE2=data2

echo " Data file $FILE1:"
cat $FILE1

echo
echo " Data file $FILE2:"
cat $FILE2

echo
echo " Results for comparison of entire files:"
cmp $FILE1 $FILE2
echo " Exit code is $?"

echo
echo " Results for comparison of files past byte 5:"
cmp -i 5 $FILE1 $FILE2
echo " Exit code is $?"

echo
echo " Results for comparison options in non-standard order:"
cmp $FILE1 $FILE2 -i 5
echo " Exit code is $?"

exit 0

Producing:

Code:
% ./s1

(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash 2.05b.0
cmp (GNU diffutils) 2.8.1

 Data file data1:
junk1 in this line.
hello, world.

 Data file data2:
junk2 in this line.
hello, world.

 Results for comparison of entire files:
data1 data2 differ: char 5, line 1
 Exit code is 1

 Results for comparison of files past byte 5:
 Exit code is 0

 Results for comparison options in non-standard order:
 Exit code is 0

Are you taking into account that the exit code is reset for each command? ... cheers, drl
  #4 (permalink)  
Old 10-08-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,889
It's not documented in the man page. Not even in the info pages. I've got the same version.
  #5 (permalink)  
Old 10-08-2008
drl's Avatar
drl drl is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 712
Hi, otheus.
Quote:
Originally Posted by otheus View Post
It's not documented in the man page. Not even in the info pages. I've got the same version.
Interesting. Are you using Linux? I have worked on unix systems where the SA installed the GNU utilities, but did not install man pages. Sometimes the GNU utilities were in odd places, and the PATHs were adjusted.

Does the utility accept the the "-i" option? ... cheers, drl
  #6 (permalink)  
Old 10-09-2008
otheus's Avatar
otheus otheus is offline Forum Staff  
Moderator ala Mode
  
 

Join Date: Feb 2007
Location: Innsbruck, Austria
Posts: 1,889
Yeah, cmp works just fine with the -i option. cmp --help shows it too. "rpm" shows that the package was installed in 2002 and that the man pages came along with it. Sounds like the man pages were never updated.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:34 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0