I need to replace a single line in a file. Generally, this code works fine:
(The actual specifics on what this block is doing is not necessary for this question).
Simply use sed, awk or Perl for the job.