in reply to redo entire loop
Sure thing, assuming your data file fits in memory, slurp it into an array first. Then make any updates. If you made no updates, you can quit; otherwise write the array to the output file.
...roboticus