Passing variables to sed

Hi Folks,

How can I make the following to work from a korn shell?

old="OLDSTRING"
new="NEWSTRING"
file="myfile.txt"
sed -n 's/$old/$new/gp' $file

Thanks in advance

rogers42

use double quotes

try this

sed -n 's/'$old'/'$new'/gp' $file

Thanks. Both the suggestions worked. Since I am planning on calling sed for the same file but for multiple strings, I notice the file takes a lot of abuse. Hence, I have decided to go with nawk.

I tried mimicking the same (following) format for the nawk utility but it does not work with nawk ?

nawk '{ gsub(/'$old'/,'$new') }' $file

Any suggestions.

Thanks in advance.

rogers42