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.

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.

 
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

add & to sed..

example:

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

I hope you can correct your logic

Thank vidyadhar,

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

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

error is :-

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.

So vidyadhar85's hope was in vain. Try

sed -e "s/$String/&\|$Url/g"

Thanks rudi for your efforts.

I tried your logic also, Same issue is there

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

Post the command/expression you ran.