in reply to Re: Search and replace within a file
in thread Search and replace within a file

You can achieve the same in a perl one liner
$perl -e 's/old/new/ -pi.backup /etc/hosts
It does the inplace replace and takes a back up of the old files with .backup extension