如何用xml中的sed替换多行字符串

时间:2017-01-18 15:40:46

标签: xml sed titanium

我有以下xml节点

<key>CFBundleShortVersionString</key>
<string>2.2.1</string>
<key>CFBundleVersion</key>
<string>2.2.1</string>

我正在努力实现这一目标:

<key>CFBundleShortVersionString</key>
<string>$buildno</string>
<key>CFBundleVersion</key>
<string>$buildno</string>

以下命令仅在删除换行符时有效:

eval "sed -i.bak  's/<key>CFBundleShortVersionString<\/key<string>2.2.*<\/string><key>CFBundleVersion<\/key><string>2.2.*<\/string>/<key>CFBundleShortVersionString<\/key<string>$NUM<\/string><key>CFBundleVersion<\/key><string>$NUM<\/string>/' tiapp.xml"

我已尝试在花括号中使用字符N但没有任何运气。

1 个答案:

答案 0 :(得分:0)

它以这种方式工作:

sed -i "" "/<key>CFBundleShortVersionString<\/key>/{n;s/<string>.*<\/string>/<string>2.2.$USER<\/string>/;}" tiapp.xml
sed -i "" "/<key>CFBundleVersion<\/key>/{n;s/<string>.*<\/string>/<string>2.2.$USER<\/string>/;}" tiapp.xml