转义一个在DOS批处理字符串替换命令等号 [英] Escaping an equals sign in DOS batch string replacement command

查看:1004
本文介绍了转义一个在DOS批处理字符串替换命令等号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用DOS批处理文件来调整它的本地机器替换JNLP文件一些文本。

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.

我要替换行,

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

与初始和最大堆大小的特定设置。

with specific settings for the initial and max heap sizes.

例如,此刻我有,

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?

推荐答案

下面是一个替代的解决方案。如果你能负担得起下载GNU工具,您可以使用 SED

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 

这篇关于转义一个在DOS批处理字符串替换命令等号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆