![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Using sed at all would be horrid. Switch to tr for this:
Code:
$ echo 123abcdefgABCDEFGHI456...DOG | tr ABCD abcd 123abcdefgabcdEFGHI456...dOG $ |
|
#3
|
||||
|
||||
|
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 |
|
#4
|
|||
|
|||
|
Quote:
|
|||
| Google The UNIX and Linux Forums |