What if we save the file with a new name and THEN replace a string?
I would cheat and program in Edlin, which has been part of DOS since the beginning.
Make a copy of your original file with a copy command and work from it.
Now say we want to find "Harry" in our new file called Names.txt, and change it to "Mary" ...
If Names.txt contains:
Tom
Dick
Harry
and NewName.txt contains
Mary
..we could do...
Edlin c:\Names.txt < c:\EdlinCommands.txt
where the EdlinCommands file contains...
"1sHarry" means start at the first line in the file and search for the word Harry
and ".d" means delete the line that contains "Harry"
and ".tNewName.txt" means transfer the contents of "NewName.txt" to this line location (.).
"e" means save and end.