in reply to Script to update a value in text file

The file on disk is a sequence of bytes. You can't simply insert or delete bytes because all the bytes after that have to be moved.

For a small file, read the file into memory, make modifications as you will and then re-write the file. You may want to make some sort of backup scheme so that if your program dies while re-writing the file, the orginal data can still be recovered (i.e. don't delete, file and re-write with the same name because if that write fails, all data is lost).

  • Comment on Re: Script to update a value in text file