in reply to Append to correct place in a file

With flat files, you have a couple of options:

Neither of these outcomes are what you want. For that reason, you have to implement one of several more appropriate strategies:

I hope this gives you some ideas to work with.


Dave