|
Answer» I am trying to create a batch file that will replace text within a text file.
I would like the batch file to prompt me to enter the text to search for, and enter what to replace that text with. If there are multiple instances of the text, I would like it to also replace all instances.
For example.... Say I wanted to replace the WORD "start" with the word "stop" The batch file would prompt me to enter text to find, I would enter the word "start" and then it would prompt me to enter the text to replace the word "start" with and I would enter the word "stop"
And if the word "start" occurred 40 times in the text file, I would like it to replace all instances with the word "stop"
I would really APPRECIATE it if someone could HELP me.
Thank you!This uses a helper batch file called `repl.bat` (by dbenham) - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat
Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.
It should be robust and also swift for large files.
Code: [Select]echo off set /p "WORDA=Enter the word to find: " set /p "WORDB=Enter the word to replace: " type "file.txt" | repl "%wordA%" "%wordB%" LI >"newfile.txt" This works perfectly.
Thank you so much!
|