replacing specific lines in a file

Hi there
I have a file which has the lines

# Serial number for hostid
EXP_SERIAL_=""

These lines could be anywhere in the file as far as line numbers go, I would like replace these two lines with

# Serial number for hostid $var1
EXP_SERIAL_$var1="$var2"

Is there a quick and simple way for me to do this ?

cheers

........................................

use this

though not clean, should work

thats great but if i run that command from the command line it outputs the correct result to the screen but doesnt actually edit the file

How do i get it to make a permanent change to the file ??

sed "s/old text/new text/g" input.txt > temp
mv temp input.txt

or

perl -pi -e "s/old text/new text/g" input.txt 

that works great thankyou ....I wanted to avoid creating a new file and mv'ing it back over again....but if i have to do that then so be it

thanks for your help

You might try something like this if you don't want to create a file:

echo '%s/oldtext/newtext/g\nwq' | ex file

This will edit the text within the file. Non interactive style vi. The exact syntax for ex is a bit murky I can't find a lot of docs on it, but in a few occasions it's well worth figuring out and using.