sed relacement of word after particular string in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed relacement of word after particular string in a file
# 1  
Old 07-18-2013
sed relacement of word after particular string in a file

Hi All,


I am trying to replace the string in a file after some particular string in the file.

I am reading both string from one input file.

Code:
localhostTest|http:\\localhost:7222

After string "locatTest" it should place the "http:\\localhost:7222"

The below logic is replacing that word in the file with input file word. I want to replace after that word.

Code:
 
InputFILE=/home/Temp/Name.txt
while IFS="|" read String Url 
do
echo "String is $String URL is $Url"
< JMS_Monitor_Template.txt sed -e "s/$String/$Url/g" > "/home/Temp/Test/Log/Server2/Server1/Monitor_Template_$Url.txt"
done < $HSFILE

# 2  
Old 07-18-2013
add & to sed..

example:
Code:
 
vidya> echo "HELLO" | sed 's/HELLO/& THERE/g'
HELLO THERE

I hope you can correct your logic
# 3  
Old 07-18-2013
Thank vidyadhar,

It is replacing the character but when am trying to replace it through variable it is giving me below error.

Code:
 
< Monitor_Template.txt sed -e "s/URL./& $url/g" > "/home/Temp/Test/Log/Server2/Server1/Monitor_Template_$url.txt"

error is :-
Code:
sed: -e expression #1, char 26: unknown option to `s'

With single quotes in command , it is replacing the hardcoded values in the command but through variable it is giving the error.
# 4  
Old 07-18-2013
So vidyadhar85's hope was in vain. Try
Code:
sed -e "s/$String/&\|$Url/g"


Last edited by RudiC; 07-18-2013 at 10:30 AM.. Reason: typo
# 5  
Old 07-18-2013
Thanks rudi for your efforts.

I tried your logic also, Same issue is there

Code:
sed: -e expression #1, char 16: unknown option to `s'

# 6  
Old 07-19-2013
Post the command/expression you ran.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace string of a file with a string of another file for matches using grep,sed,awk

I have a file comp.pkglist which mention package version and release . In 'version change' and 'release change' line there are two versions 'old' and 'new' Version Change: --> Release Change: --> cat comp.pkglist Package list: nss-util-devel-3.28.4-1.el6_9.x86_64 Version Change: 3.28.4 -->... (1 Reply)
Discussion started by: Paras Pandey
1 Replies

2. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies

3. Shell Programming and Scripting

sed command to remove a word from string

Hello All, I am running a command find . -name amp.cfg | cut -c 3- which gives me output something like below rel/prod/amp.cfg rel/fld/amp.cfg deb/detail/amp.cfg deb/err/amp.cfg I want to remove trailing "/amp.cfg" so that i should get output something like... (7 Replies)
Discussion started by: anand.shah
7 Replies

4. Shell Programming and Scripting

Using SED to extract a word or string.

I am working with the ksh shell in HP UNIX and I am attempting to extract a word, beginning with a particular string and ending at the first space. for example I want to extract the word or string MS_RECENT_ACTIVITY from the following string " This has been entered in MS_RECENT_ACTIVITY the... (2 Replies)
Discussion started by: simpletech369
2 Replies

5. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

6. Shell Programming and Scripting

replace (sed?) a single line/string in file with multiple lines (string) from another file??

Can someone tell me how I can do this? e.g: Say file1.txt contains: today is monday the 22 of NOVEMBER 2010 and file2.txt contains: the 11th month of How do i replace the word NOVEMBER with (5 Replies)
Discussion started by: tuathan
5 Replies

7. Shell Programming and Scripting

awk or sed command to print specific string between word and blank space

My source is on each line 98.194.245.255 - - "GET /disp0201.php?poc=4060&roc=1&ps=R&ooc=13&mjv=6&mov=5&rel=5&bod=155&oxi=2&omj=5&ozn=1&dav=20&cd=&daz=&drc=&mo=&sid=&lang=EN&loc=JPN HTTP/1.1" 302 - "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR... (5 Replies)
Discussion started by: elamurugu
5 Replies

8. Shell Programming and Scripting

Using sed to replace a string in file with a string in a variable that contains spaces

Hi, i call my shell like: my_shell "my project name" my script: #!/bin/bash -vx projectname=$1 sed s/'PROJECT_NAME ='/'PROJECT_NAME = '$projectname/ <test_config_doxy >temp cp temp test_config_doxy the following error occurres: sed s/'PROJECT_NAME ... (2 Replies)
Discussion started by: vivelafete
2 Replies

9. Solaris

board relacement in solaris server

HI Can anyone clarify my doubt.V are using two SUN V890 servers.At present the board in t passive node is 1.5 ghz and due to over load we are plannin to remove the board from passive node and insert it in active node and then insert a 1.3ghz board in passive node..will it be possible if so... (3 Replies)
Discussion started by: madanmeer
3 Replies

10. Shell Programming and Scripting

Replace a word with string from another file

Hi, this belongs a little to my other post but only at the starting point. With find -name "*.htm*" i got a list like this: ./1999/01/file1.html ./1999/01/file2.html ./1999/02/file1.html ./2000/04/file1.html ./2000/04/file2.html ./2000/04/file3.html ./2000/file1.html... (2 Replies)
Discussion started by: Tonda
2 Replies
Login or Register to Ask a Question