Q: How can I insert or delete a line (or record) in the middle of a file?
A: In general, there is no way to do this. [footnote] The usual solution is simply to rewrite the file.
When you find yourself needing to insert data into an existing file, here are a few alternatives you can try:
Instead of actually deleting records, you might consider just marking them as deleted, and having the code which reads the file ignore them. (You could run a separate coalescion program once in a while to rewrite the file, finally discarding the deleted records. Or, if the records are all the same length, you could take the last record and use it to overwrite the record to be deleted, then truncate the file.)
See also questions 12.30 and 19.13.
Additional links: further reading