问题描述
我正在尝试制作一个可以更改一些值然后部署的脚本。我有这个XML:
I'm trying to make a script that changes a few values then deploys. I have this XML:
<application>
<NVPairs name="Variables">
<NameValuePair>
<name>Parameter/1</name>
<value>MyOtherValue</value>
</NameValuePair>
<NameValuePair>
<name>Parameter/2</name>
<value>MyValue</value>
</NameValuePair>
</NVPairs>
</application>
我要使用SED进行编辑。 NVPAIRS和NameValue似乎让我有些混乱。我可以问一些如何处理NameValuePair的建议吗?我也尝试过XMLStarlet,但存在相同的问题。似乎无法处理NameValuePairs。
Which I am trying to edit with SED. The NVPAIRS and NameValue seems to be messing me around a bit. Can I ask for suggestions how to deal with NameValuePair? I did try XMLStarlet as well, but same problem. Can not seem to deal with NameValuePairs.
推荐答案
我不会尝试使用sed编辑XML。除非有一个常数要匹配(让您决定是/ 1还是/ 2),否则将很难(我会说这是不可能的,但某些sed大师会鸣叫并证明我错了...)
I wouldn't try to use sed to edit XML. Unless there is some constant to match on (that lets you decide if you are on a /1 or /2) it'll be hard (I would say impossible, but some sed guru will chime and and prove me wrong...)
如果您无法安装内容,则可以使用诸如awk或perl脚本之类的东西来保持最低状态,而不是sed。
If you can't install stuff, something like an awk or perl script that lets you keep a minimum of state you work better than sed.
这篇关于在Linux上使用Shell脚本从命令行编辑XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!