I have written a batch script to find and replace a string in a text file. Following is my script.
@echo off &setlocal
set "search=%1"
set "replace=%2"
set "textfile=Input.txt"
set "newfile=Output.txt"
(for /f "delims=" %%i in (%textfile%) do (
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:%search%=%replace%!"
echo(!line!
endlocal
))>"%newfile%"
del %textfile%
rename %newfile% %textfile%
I am able to replace the word successfully.
But i dont want to create Output.txt and then rename it the original file..
Please help me out for editing a text file without redirecting the output to a new file..