![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| help needed in fuser command | anju | Shell Programming and Scripting | 1 | 02-20-2008 02:08 AM |
| help needed in ls command | anju | Shell Programming and Scripting | 1 | 02-18-2008 07:20 AM |
| Help needed on Date command | nikunj | Shell Programming and Scripting | 5 | 07-08-2006 12:37 PM |
| Help needed for ps command in AIX | moe2266 | AIX | 0 | 09-30-2005 12:43 PM |
| help needed for sed command | manualvin | UNIX for Dummies Questions & Answers | 2 | 06-25-2004 12:41 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
SED command ---------help needed
Hi all
I am new babie to shell script, so please advise me n help me . suppose i have a string "abacus sabre", i need to replace occurences 'ab' with 'cd' and i need to store this result into same string and i need to return this result from script to the calling function, where as the string is passed from calling function. i tried like this mainStr="abacus" old_word="ab" new_word="cd" result=`sed -i s/$old_word/$new_word $mainstr ` return $result |
|
||||
|
Hi Reddy,
The below script will work for you, mainStr="abacus" old_word="ab" new_word="cd" result=`cat $mainStr | sed "s/$old_word/$new_word/g"` Last edited by apsprabhu; 03-17-2008 at 08:58 AM.. Reason: Missed out |
|
|||||
|
Hi
This is the same question you posted in: Need help regarding replacing a part of string Please folow the forum rules and do not multiple post.... however...following examples should help you on your way a little: Code:
# mainstr="abacus sabre" # echo $mainstr abacus sabre # echo $mainstr | sed 's/ab/cd/g' cdacus scdre # echo $mainstr abacus sabre # mainstr=`echo $mainstr | sed 's/ab/cd/g'` # echo $mainstr cdacus scdre |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|