I search up that there are some scripts to do the insert job after certain line or certain string. However, if the insert string contain <abcdef> it can not do the insert any more, complain the
The syntax of the command is incorrect.
How we can solve this problem.
For example, I have a xml file sample.xml
I would like to insert one line <serial_number id="serial_number">CT100000PT000271</serial_number> after line 877
I tried the below code
Code: Select all
setlocal DisableDelayedExpansion
set randomline=877
set "lineno=0"
(
FOR /F "delims=" %%L in ('findstr /n "^" sample1.xml') do (
set /a lineno+=1
set "line=%%L"
setlocal EnableDelayedExpansion
if "!lineno!"=="%randomline%" call :insertblock
set "line=!line:*:=!"
(echo(!line!)
endlocal
)
) > sample2.xml
exit /b
:insertblock
echo <serial_number id="serial_number">CT100000PT000271</serial_number>
if you removed < and > from <serial_number id="serial_number">CT100000PT000271</serial_number> it is fine. So how we deal with < and > in the string?
Any thoughts we can do this job?
Thanks
WY