Batch script text replace issue
Posted: 21 Nov 2012 01:17
Hi Guys,
I have to write a batch file which will replace the matching word from the text file. everything is fine with below script except a character '[' deletes from new created file.
I am using this script to replace my old value to new value but delims value ] is also deleted from the new file.
Please guild me how can I replace the text without deleting any character value.
@echo Off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION
if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
set "line=%%B"
if defined line (
call set "line=echo.%%line:%~1=%~2%%"
for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
) ELSE echo.
)
I have to write a batch file which will replace the matching word from the text file. everything is fine with below script except a character '[' deletes from new created file.
I am using this script to replace my old value to new value but delims value ] is also deleted from the new file.
Please guild me how can I replace the text without deleting any character value.
@echo Off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL DISABLEDELAYEDEXPANSION
if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF
for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do (
set "line=%%B"
if defined line (
call set "line=echo.%%line:%~1=%~2%%"
for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X
) ELSE echo.
)