![]() |
|
|
|
|
|||||||
| 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 |
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Code:
eval sed 's/xena/`hostname`/' file |
|
#3
|
|||
|
|||
|
no need for eval
Code:
sed "s/xena/`hostname`/" file |
|
#4
|
||||
|
||||
|
true - bad habit of mine overusing eval :-)
|
|
#5
|
|||
|
|||
|
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 |
|
#6
|
||||
|
||||
|
bit clunky but:
Code:
sed "s_=/.*/sybase_=/`hostname`/sybase_" file |
|
#7
|
||||
|
||||
|
Code:
sed -e "s/\(install_location=.\)[^/]*\(\/.*\)/\1`hostname`\2/g" file |
||||
| Google The UNIX and Linux Forums |