in reply to seek in a text file

Now that you've got a solution to your problem, let me suggest that you not do this. Instead of overwriting the file, write the filtered contents to a new file name. Or rename the original file before writing the filtered contents to the specified filename.

This provides an audit trail for what you've done, and guarantees you can fall back to the original contents should the need arise.