The short answer is no.
Long answer: Actually, no. If you know that the text you insert directly replaces the text you delete, you can perform the substitution by accessing the part of the file, reading a small block, replacing the new text and replacing this block. This will work as an example of replacing your age, but not if you replace 9 with 10 or 99 with 100, for example.
However, there are other difficulties:
You may have variable-length strings, so you don't know where to look. You still have to read the file to the place where you are doing the replacement, even if you do it block by block at a time and discard unwanted ones.
You have one more difficulty with multibyte character sets such as UTF-8. Your incoming text may appear the same length as the outgoing text, but may be shorter or longer depending on the substitution.
e (U + 0065) is encoded as one byte, but Γ© (U + 00E9) is encoded as two.
But, if you are just looking for a less intensive amount of memory, you can read the file one line at a time and write each line to a new file when processing it. When you are done, delete the old file and rename the new one. This can be slow, so buffering reads and writes from, say, 20 lines (or 100, or 1000, or whatever you choose ..) will improve performance.
user1864610
source share