read open dump all to a variable (in memory) apply a substitution to this variable close re-open the file, now for writing print the changed variable to the file (overwrite the whole file) and close again