The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 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 11:37 AM
Help needed for ps command in AIX moe2266 AIX 0 09-30-2005 11:43 AM
help needed for sed command manualvin UNIX for Dummies Questions & Answers 2 06-24-2004 11:41 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-17-2008
veerapureddy veerapureddy is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 2
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
  #2 (permalink)  
Old 03-17-2008
apsprabhu apsprabhu is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 43
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
  #3 (permalink)  
Old 03-17-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 414
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
  #4 (permalink)  
Old 03-17-2008
mmoutairek mmoutairek is offline
Registered User
  
 

Join Date: Mar 2008
Posts: 1
how do i delete duplicate lines with sed.can anyboda help me plz...!
  #5 (permalink)  
Old 03-17-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
mmoutairek,

Please don't hijack another's thread with your unrelated question but start a new thread.

Regards
Sponsored Links
Closed Thread

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:40 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0