我有一个.xml
文件,我必须在其中搜索“ <reviseddate>
”标签。它可以在文件中出现多次。如果是这样,我必须将“ <reviseddate>
”标签替换为“ <reviseddate1>
”,我需要一个 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