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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl from bash script arsidh Shell Programming and Scripting 10 06-04-2008 09:25 AM
bash. convert mpeg adts to normal mp3 stahoo23 Shell Programming and Scripting 5 05-18-2008 02:26 AM
Urgent!! Bash - problem using CD with variable jacksam007 Shell Programming and Scripting 1 01-17-2007 07:10 PM
URGENT,URGENT- Need help tape drive installation sriny UNIX for Advanced & Expert Users 3 11-16-2006 11:43 AM
URGENT---URGENT--No OK PROMPt after RSC CONFIG sriny SUN Solaris 7 10-29-2006 07:06 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-18-2004
Registered User
 

Join Date: Apr 2004
Location: sydney
Posts: 4
Stumble this Post!
Convert bash to sh URGENT :(

Hi,

I have to write a program to compare 2 files for copying.

the program is ran on Solaris 5.8 like this:
script.sh file1.txt file2.txt

I wrote the program using bash and it took me forever since I am a beginner but it works very well.

I'm getting so close to the deadline and I realised today that actually I have to use normal Bourne shell (bin/sh) and not bash(bin/bash).

Could anyone PLEASE help me to adjust my script (like replacing arrays..) I'm just getting so desperate....

I just attach a file with the script and also 2 little text files to run the script.

PLEASE HELP me anyone! Thank you so much!


Chris.
Attached Files
File Type: zip dupscript.zip (1.4 KB, 6 views)
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-18-2004
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,211
Stumble this Post!
I think you will have less work changing your logic than adapting your script to sh.
Try something like this :
Code:
File1=$1
File2=$2

Work=/tmp/`basename $0`.$$
Work1=$Work.1
Work2=$Work.2

tr -d '[:blank:]' < $File1 | sort -o $Work1
tr -d '[:blank:]' < $File2 | sort -o $Work2

LINES_MATCHING=`comm -1 -2 $Work1 $Work2 | wc -l | awk '{print $1}'`
LINES_TOTAL=`wc -l $Work1 | awk '{print $1}'`
LINES_NOT_MATCHING=`expr $LINES_TOTAL - $LINES_MATCHING`
PERCENT_NOT_MATCHING=`expr $LINES_NOT_MATCHING \* 100 / $LINES_TOTAL`

rm -f $Work1 $Work2

echo "Matched: $LINES_MATCHING"
echo "Not Matched: $LINES_NOT_MATCHING  ($PERCENT_NOT_MATCHING%)"
echo "Total: $LINES_TOTAL"
Reply With Quote
  #3 (permalink)  
Old 04-18-2004
Registered User
 

Join Date: Apr 2004
Location: sydney
Posts: 4
Stumble this Post!
That's what I thought, I just have to change it all....... short night ahead....!



Chris
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0