我有一个.xml
文件,其中我必须搜索“<reviseddate>
”标记。它可以在文件中出现多次。如果是这样我不得不更换“<reviseddate>
”标记为“<reviseddate1>
”我需要为这个用于使用递增值替换字符串的shell脚本
文本的样本是一个shell脚本如下:
Manuscript received <receiveddate>June 7, 2005</receiveddate>; revised
<reviseddate> February 4, 2006 </reviseddate>, <reviseddate> August 14, 2006 </reviseddate>,
and <reviseddate> October 7, 2006 </reviseddate>. This work was supported by the
<supported><agency-name>California Department of Transportation through the California
Center for Innovative Transportation and the California Partners for Advanced Highway
and Transit Program</agency-name><grant-grp/></supported>. The contents of this paper
reflect the views of the authors and do not necessarily indicate acceptance by the
sponsors. The Associate Editor for this paper was M. M. Sokoloski.</affnote-para>
输出应该如下
Manuscript received <receiveddate> June 7, 2005 <receiveddate>; revised
<reviseddate1> February 4, 2006 </reviseddate1>, <reviseddate2> August 14, 2006 </reviseddate2>,
and <reviseddate3> October 7, 2006 </reviseddate3>. This work was supported by the
<supported><agency-name>California Department of Transportation through the California
Center for Innovative Transportation and the California Partners for Advanced Highway
and Transit Program</agency-name><grant-grp/></supported>. The contents of this paper
reflect the views of the authors and do not necessarily indicate acceptance by the
sponsors. The Associate Editor for this paper was M. M. Sokoloski.</affnote-para>
我已经试过:
for i in $c do
sed -e "s/<reviseddate>/<reviseddate$i>/g" $path/$input_file > $path/input_new.xml
cp $path/input_new.xml $path/$input_file
rm -f input_new.xml
done
请解码您的问题。 – Anubhab 2013-03-08 07:47:18
for i in $ c do sed -e“s///g”$ path/$ input_file> $ path /input_new.xml cp $ path /input_new.xml $ path/$ input_file rm -f input_new.xml done –
Mallik
2013-03-08 08:19:01
使用XML解析器;他们可用于多种语言。 – chepner 2013-03-08 16:00:31