问题
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>
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.
回答1:
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...)
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.
来源:https://stackoverflow.com/questions/17592740/edit-xml-from-command-line-with-shell-script-on-linux