in reply to The easiest way to substitute a part of the content of a file.

For a short one-off I would recommend using the switches out of perlrun:
perl -pi.bak -e 's/content/newcontent/g' fileloc
(Use " instead of ' on Windows.)

For longer programs, you really do need to read it, manipulate a string, then write it again.

  • Comment on Re (tilly) 1: The easiest way to substitute a part of the content of a file.
  • Download Code