我有一個.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