Writing a simple script to find and replace a character in batch.my script contains " character which i want to replace it with some text like ".Please let me which escape character would help .Tried "" and ^" it did not work Script : `
@echo off &setlocal
set search2="""
set "replace2=""
set "textfile=D:\Users\manajosh\Desktop\try-Copy.xml"
set "newfile=D:\Users\manajosh\Desktop\Output.txt"
(for /f "delims=" %%i in (%textfile%) do (
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:%search2%=%replace2%!"
echo(!line!
endlocal
))>"%newfile%"
pause 6
`
try this technique:
@echo off
set "search2=""
rem set search2="""
set "replace2=""
set "line="quoted""
setlocal enableDelayedExpansion
for /f "usebackq tokens=1,2 delims=§" %%a in ('"!search2!"§"!replace2!"') do echo "!line:%%~a=%%~b!"
endlocal
the thing is you need delayed expansion for line and also the search2 and replace2 - and this can be achieved with wrapping for loop.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.