UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 13th, 2006, 11:22 PM
gkrishnag gkrishnag is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 2 gkrishnag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 11 m 2 sec
Reputation Power: 0
Need Script Corrections...(Shell)

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...

i have changed the code like below still iam getting the above error..

while read line
do
typeset -L2 string
string=$line
if [[ "$string" == " < " ]] ; then
echo ${line#$string} is removed.
fi;;

typeset -L2 string
string=$line
if [[ "$string" == " > " ]] ; then
echo ${line#$string} is added.
fi;;
Any Sugesstions...

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Need Script Corrections...(Shell)


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway