[英]Linux command to insert multiple lines into xml file
Linux命令在匹配/模式之前将多行插入xml文件。 尝试使用以下命令:
#finding pattern:
toOccurance=`grep -n "\<copy file=\"${appletResource}\/images\/CCMsplash.gif\" toFile=\"${appletbuild}\/splash.gif\" \/>" abc.xml | awk -F: '{print $1}'`
toOccurance=$(($toOccurance -1 ))
sed -i "$toOccurance /a \<copy todir=\"${controlbuild\}\" flatten=\"true\">\n
\<fileset dir=\"${appletResource}\">\n
\<include name=\"crop.properties\"\/>\n
\<include name=\"vvm.xml\"\/>\n
\<exclude name=\"images\/\*splash.gif\"\/>
<\/fileset>
<\/copy>" abc.xml
没有显示错误,但命令不起作用。 关于如何解决它的任何指针?
您的sed“ a”命令错误。 更改:
sed -i "$toOccurance /a blah blah blah....
至
sed -i "${toOccurance}a blah blah blah....
但是@tripleee是正确的,您也可以使用sed
查找行号,而不是顶部的所有业务。 但是,我猜一个工作脚本值得两个“这样会更好”的脚本 。
函数updateXML(){abcFilePath = abc.xml echo“更新文件$ abcFilePath”
if [ -f $abcFilePath ];
then
echo "File $abcFilePath exists"
else
echo "File $abcFilePath does not exists"
dos2unix $abcFilePath
fi
toOccurance=`grep -n '\<copy file=\"${appletResource}\/images\/CCMsplash.gif\" toFile=\"${appletbuild}\/splash.gif\" \/>' $abcFilePath | awk -F: '{print $1}'`
toOccurance=$(($toOccurance - 1 ))
echo "toOccurance = $toOccurance"
sed -i“ $ {toOccurance} a \\ n \\\\ n \\\\ n \\\\ n \\ n </ fileset> \\ n </ copy>” $ abcFilePath
回显“更新的文件”
}
updateXML
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.