stringdosbatch-file

Escaping an equals sign in DOS batch string replacement command


I need to replace some text in a JNLP file using a DOS batch file to tune it for the local machine.

The problem is that the search pattern contains an equals sign which is messing up the string replacement in the batch file.

I want to replace the line,

<j2se version="1.5" initial-heap-size="100M" max-heap-size="100M"/>

with specific settings for the initial and max heap sizes.

For example at the moment I have,

for /f "tokens=* delims=" %%a in (%filePath%agility.jnlp) do (
set str=%%a
set str=!str:initial-heap-size="100M"=initial-heap-size="%min%M"!
echo !str!>>%filePath%new.jnlp)

but the = in the search pattern is being read as part of the replacement command.

How do I escape the equals sign so it is processed as text?


Solution

  • Here's an alternative solution. If you can afford to download GNU tools, you can use sed:

    C:\test>set a=200
    C:\test>sed -i.bak "s/^\(.*initial-heap-size=\"\).*\( max.*\)/\1%a%\"\2/" file