sed doubt...

Hi,

i need find and replace a sting with a new variable having value as spaces in between.

Eg:

set a = "i am variable"
set b = "i am second"

sed -e 's/find_string/'$a'/g' -e 's/find2_str/'$b'/g' input_file

here it is giving error...

How to get an varaible, which is having space..

Thanks in advance,
Vasanth

---------- Post updated at 08:42 AM ---------- Previous update was at 08:33 AM ----------

Hi

anybody there to help me on this issue.

Vasanth

sed "s/find_string/$a/g;s/find2_str/$b/g" input_file

Hi,

i tried the below code

sed "s/find_string/$a/g;s/find2_str/$b/g" input_file

But, variable substituion fails and the replace is coming as $a only. Not the value..

Thans in advance,
Vasanth

And you're sure you used double and not single quotes?

yes...

i used double Quotes..

Thanks

Could you post the output from the following commands:

ps -p$$
set a = "i am variable"
set b = "i am second"
printf "%s\n%s\n" ok ok | sed "s/ok/$a/;s/ok/$b/"

This worked for me..

a="i am variable"
b="i am second"
sed -e "s/find_string/$a/g" -e "s/find2_str/$b/g" input_file