Change the line:
Code:
sed -e 's/$pattern/newpattern/' $file > $file.tmp
to
Code:
sed -e "s/$pattern/newpattern/" $file > $file.tmp
The single quotes (') wouldn't do variable expansion and hence there would be no replacement. Which is why we need double quotes there (")
Besides, you can also replace:
Code:
sed -e 's/$pattern/newpattern/' $file > $file.tmp
mv $file.tmp $file
with
Code:
sed -i "s/$pattern/newpattern/" $file
which would edit the file itself. You can check the man page for details.
Thanks,
NNS