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
Bacula: backups that don't suck iBot UNIX and Linux RSS News 0 04-23-2008 01:40 AM
UNIX newbie NEWBIE question! Hanamachi UNIX for Dummies Questions & Answers 3 09-14-2006 07:23 AM
Newbie in need of help cfjohnsn UNIX for Dummies Questions & Answers 3 05-17-2006 03:10 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-09-2006
vbm vbm is offline
Registered User
 

Join Date: Nov 2006
Posts: 10
newbie please help, i suck!!!

hey this is my first post here and i am desperately looking for some help! Im trying to write a shell script for the first time and ive run into some issues.

Im writing a script that takes two strings as parameters, im then using sed to do replacements of the first string over the second string for given files.

eg sed "sl/$1/$2/g" "$file"

so this works fine and replaces the whole string with the whole string, now i need to work char by char. So given inputs of $1=abcd $2=ABCD, i need sed to replace all instances of a with A, b with B, c with C etc. Ive tried a few things already, and the way i was attempting was calling sed -e for each char, this is obviously a horrid way of doing it :P

Im not a programming noob by any stretch of the word but this is giving me real issues Any help would be appreciated, thanks.
Reply With Quote
Forum Sponsor
  #2  
Old 11-09-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,652
Using sed at all would be horrid. Switch to tr for this:
Code:
$ echo 123abcdefgABCDEFGHI456...DOG   | tr ABCD abcd
123abcdefgabcdEFGHI456...dOG
$
Reply With Quote
  #3  
Old 11-09-2006
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
I agree that tr is definitely the tool of choice here, but it wouldn't be too tricky with sed either:

Code:
$ STR1="abcd"
$ STR2="ABCD"
$ echo "123abcdefABCDEFGHI456...DOG" | sed "y/$STR2/$STR1/"
123abcdefabcdEFGHI456...dOG
Reply With Quote
  #4  
Old 11-09-2006
vbm vbm is offline
Registered User
 

Join Date: Nov 2006
Posts: 10
Quote:
sed "y/$var1/$var2/"
OMG I KNEW there was a painfully simple way of doing what i wanted!! You have no idea the pain that has caused me, about 3 solid hours trying all sorts of kludges to get it to go. that'll teach me not to read th man pages thoroughly enough! Thankyou so much, i feel like such a retard :P
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:51 PM.


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

Content Relevant URLs by vBSEO 3.2.0