Variables within a sed statement

I am just wondering if it's possible to refer to variables within a sed statement as follows:-

cat $file | sed -e 1's/$oldtext/$newtext/' > $file

as when I run the script, the variables are not recognised and nothing happens..??

Thanks

Turn off the quoting:

cat $file | sed -e 1's/'$oldtext'/'$newtext'/' > $file

here can be used also

cat $file | sed -e 1s/$oldtext/$newtext/ > $file

if $oldtext, $newtext don't contain special symbols, or better

cat $file | sed -e "1s/$oldtext/$newtext/" > $file

UUoC.....

sed 'some_sed_cmd' infile > outfile

Cheers
ZB

Nice one - the single quotes around the variables has worked. thanks

It's not correct definition of quoting in the shell, to make this question clear look at

Hi Hitori & all

well I did some reading as you suggested, however from the link below (http://www.student.northpark.edu/pemente/sed/sedfaq4.html\#s4.30\)
and the just to clarify, the correct way is to use double quotes (" ") around the sed statement, when refering to $variables
thanks