Replace a string in a text file
@echo off
:: replace [file] "[search_string]" "[replace_string]"
call :replace stage2.cmd "aaa bbb" "xxx yyy"
goto :EOF
:replace
@echo off
del Newxyz.txt
SETLOCAL EnableDelayedExpansion
for /f "tokens=* delims= " %%a in (%1) do (
set str=%%a
set str=!str:%~2=%~3!
echo !str!>>Newxyz.txt
)
del %1
copy Newxyz.txt %1
del Newxyz.txt
ENDLOCAL
goto :EOF