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
Search, replace string in file1 with string from (lookup table) file2? gstuart Shell Programming and Scripting 2 04-11-2008 11:32 AM
replace string in XML with sed chiru_h Shell Programming and Scripting 6 04-09-2008 04:49 PM
replace string sam99 Shell Programming and Scripting 4 03-03-2008 10:39 PM
SED Replace String Help prash184u Shell Programming and Scripting 2 01-22-2008 10:57 PM
Replace string B depending on occurence of string A hemangjani Shell Programming and Scripting 1 12-05-2006 02:10 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-17-2008
Registered User
 

Join Date: Nov 2006
Posts: 187
replace a string

hello

I have a file where an entry needs to be modified. an example of this entry is:

install_location=/xena/sybase/ase12_5

I need to replace xena with another hostname (`hostname` output) for example:

install_location=/dx1/sybase/ase12_5

how to do that?

thanks
Reply With Quote
Forum Sponsor
  #2  
Old 01-17-2008
Tytalus's Avatar
Registered User
 

Join Date: Jun 2003
Location: Scotland
Posts: 290
Code:
 
eval sed 's/xena/`hostname`/' file
should work
Reply With Quote
  #3  
Old 01-17-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
no need for eval
Code:
sed "s/xena/`hostname`/" file
Reply With Quote
  #4  
Old 01-17-2008
Tytalus's Avatar
Registered User
 

Join Date: Jun 2003
Location: Scotland
Posts: 290
true - bad habit of mine overusing eval :-)
Reply With Quote
  #5  
Old 01-17-2008
Registered User
 

Join Date: Nov 2006
Posts: 187
thanks. but the string may change:

install_location=/xena/sybase/ase12_5

I want everything between =/ and /sybase to be replaced with the hostname

thx
Reply With Quote
  #6  
Old 01-17-2008
Tytalus's Avatar
Registered User
 

Join Date: Jun 2003
Location: Scotland
Posts: 290
bit clunky but:

Code:
 sed "s_=/.*/sybase_=/`hostname`/sybase_" file
should work
Reply With Quote
  #7  
Old 01-17-2008
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Code:
sed -e "s/\(install_location=.\)[^/]*\(\/.*\)/\1`hostname`\2/g" file
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 06:34 AM.


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