我有以下XML文件更換某些行用awk
<parameters pca-dim="32"/>
<parameters resize_minpix="100000" npix="100000" ptch="24" step="4" nscale="5" maxscale="4"/>
<parameters notify-classes-removed="1"/>
<parameters grid-regions="1x1,1x3"/>
<feature_extractions>
<feature_extraction id="orh" params="8,4:0.7,0.5:0.4,0.6:0.01"/>
<feature_extraction id="col" params="4:mv:0.4,0.6:0.01"/>
</feature_extractions>
<vocabulary rebuild="IfDoesNotExist" gmm-iter="8" sig-norm-type="l2" sig-norm-pow="0.5"/>
<classifier type="sgd" lambda="1.0E-5" max-iterations="20"/>
<validation name="V1CrossValidation" folds="5" mode="fast" method="modulo" result-file="/opt/ADL_db/Users/mkhalil/CshellTest/ScriptTests/temp/V1CrossValidation-results.stats" score-flags="combine,normalize"/>
</gvcmodelinfo>
<classes>
<class name="Car">
<imageset imagedb="/opt/ADL_db/Users/mkhalil/runtime-ImageDB/DB1/db.xml" path="//image/scenes/scene[((@name="Car" or starts-with(@name,"Car")))]/ancestor::image"/>
</class>
<class name="MotorCycle">
<imageset imagedb="/opt/ADL_db/Users/mkhalil/runtime-ImageDB/DB1/db.xml" path="//image/scenes/scene[((@name="MotorCycle" or starts-with(@name,"MotorCycle")))]/ancestor::image"/>
</class>
<class name="Van">
<imageset imagedb="/opt/ADL_db/Users/mkhalil/runtime-ImageDB/DB1/db.xml" path="//image/scenes/scene[((@name="Van" or starts-with(@name,"Van")))]/ancestor::image"/>
</class>
</classes>
</gvcmodel>
,我想換成兩件事情:
/opt/ADL_db/Users/mkhalil/CshellTest/ScriptTests/temp/V1CrossValidation-results.stats
到/opt/ADL_db/Users/mkhalil/code/V1CrossValidation-results.stats
/opt/ADL_db/Users/mkhalil/runtime-ImageDB/DB1/db.xml
到/opt/ADL_db/Users/mkhalil/code/db.xml
然後用輸出創建一個新的xml文件。
你有什麼試過的?另外,請注意,如果您由於某種原因而被困在awk中,那麼您的解決方案將受到限制,因爲awk本身不會理解XML。使用perl,php,python,ruby等語言會更好。或者您可以使用其中一種awk或gawk擴展來爲awk添加基本的XML支持。 Google的「xml awk」提供了一些想法。一旦您有一些代碼可以幫助我們,請回過頭來提問。 – ghoti