The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Comparing 2 files hdixon UNIX for Dummies Questions & Answers 2 08-01-2007 12:24 PM
On comparing two number getting error,not able to rectify it pplease help moh_hak_786 Shell Programming and Scripting 2 06-24-2007 11:55 PM
comparing two files marwan UNIX for Dummies Questions & Answers 6 06-11-2007 02:39 AM
comparing shadow files with real files terrym UNIX for Advanced & Expert Users 4 02-09-2007 02:38 AM
shell script comparing files in a file raina_nalin Shell Programming and Scripting 4 06-21-2005 06:00 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-13-2006
gkrishnag gkrishnag is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 49
Script error.. for comparing 2 files!

Hi

I am using the below script to compare two files.. i am getting error as mentioned below:
#!/bin/sh
# Script to find the difference between 2 files
# Remember the old file file1 should always be the first argument. Else, the logic would reverse.
# diff.sh <old file> <new file>
if [[ $# -ne 2 ]] ; then
echo "Need just 2 files to compare"
exit 1
fi;

# Take the diff by ignoring the blank and whitespaces.
diff -b -w ${1} ${2} > ${1}.diff
if [[ $? -eq 0 ]] ; then
echo "No files were added/removed"
else
echo "Files were added/removed"
fi;

# process the diff file.
# A line might look like
# < text-which-went-out
# > text-which-came-in

while read line
do
if [[ ${line:0:2} == "< " ]] ; then
echo ${line:2} is removed.
fi;

if [[ ${line:0:2} == "> " ]] ; then
echo ${line:2} is added.
fi;

done < ${1}.diff

when i run:diff.sh <oldfilename> <newfilename>
/home/cvs ->diff.sh 2047files.txt 2048files.txt
Files were added/removed
diff.sh[23]: ${line:0:2}: The specified substitution is not valid for this command.

can some one correct this...

Note; But my puruse is done, i am able to create a another file where i could see the diff, but i get the error... how do i will over come this???

Any sugesstions...
  #2 (permalink)  
Old 09-13-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
You never mentioned which OS. Try changing #! /bin/sh to #! /bin/bash
  #3 (permalink)  
Old 09-13-2006
gkrishnag gkrishnag is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 49
Quote:
Originally Posted by vino
You never mentioned which OS. Try changing #! /bin/sh to #! /bin/bash
we r using solaris...

can some one correct the above
  #4 (permalink)  
Old 09-13-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
If using Solaris, bash may not be installed. Use ksh. Change the #!/bin/sh to #!/bin/ksh. I don't know if what you are trying works with ksh or not though.
  #5 (permalink)  
Old 09-13-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by blowtorch
If using Solaris, bash may not be installed. Use ksh. Change the #!/bin/sh to #!/bin/ksh. I don't know if what you are trying works with ksh or not though.
The construct ${line:0:2} will not work with ksh. You will have to rewrite that part of the code. Use typeset. Something like
Code:
typeset -L2 string
string=$line
if [[ "$string" == "< " ]] ; then
echo ${line#$string} is removed.
fi;
Sponsored Links
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 07:30 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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