You have to
- Read the file in memory.
- modify memory content.
- write back modified memory content to the original file (overwriting it).
You may also produce the output 'on the fly', that is copying input to the output until you find the value that must be changed, then write the changed values and repeat such steps until the end of the file. At the end you have to overwrite the input file with the output one content.