我有以下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但没有任何运气。
答案 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