Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I successfully replace text with batch in XML

I have tried to replace in my XML page a string using batch but I can't succeed to replace it fully.

I have this batch code:

@echo off
setlocal EnableDelayedExpansion
set _search=logLevel^="3"
set _replace=logLevel^="4"

for /F "delims=*" %%a in (config.xml) do (
set line=%%a
setlocal EnableDelayedExpansion
>> newconfig.xml echo(!line:%_search%=%_replace%!
endlocal
)
echo "done"
pause >nul

And I am trying to modify this line of code in my XML:

<logger logfileDirectory="path/to/logging/" logLevel="3"/>

...from logLevel="3" to logLevel="4":

<logger logfileDirectory="path/to/logging/" logLevel="4"/>

But it always returns me:

<logger logfileDirectory="path/to/logging/" "3"=logLevel="4"="3"/>

What did I do wrong?

like image 702
Daniel Treica Avatar asked Feb 17 '26 03:02

Daniel Treica


1 Answers

Take a look at replacer.bat

call replacer.bat "e?C:\content.txt" "<logger logfileDirectory=\u0022path/to/logging/\u0022 logLevel=\u00223\u0022/>" "<logger logfileDirectory=\u0022path/to/logging/\u0022 logLevel=\u00224\u0022/>"

you can check also FindRepl and JRepl which are more sophisticated tools

like image 141
npocmaka Avatar answered Feb 19 '26 06:02

npocmaka