Earlier, I described a way to replace all occurrences of a particular pattern with another in a file and write the change(s) back into that file. BBBart on #linuxpakistan on irc.freenode.net suggested another way of doing it that does not involve calling another process. It uses the “-i” switch to sed(1), something I did not know of owing to the particular manpage for sed(1) on my system not documenting it. Here’s the alternative:
ayaz$ sed -i bak 's/pattern/replace/g' file
Note, however, that I have GNU sed version 3.02 installed and it doesn’t recognise the “-i” switch. I guess this funtionality is introduced in latter versions of sed.