使用awk

时间:2016-03-04 13:10:17

标签: xml awk

我有以下xml文件

<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>

我想替换两件事:

  1. /opt/ADL_db/Users/mkhalil/CshellTest/ScriptTests/temp/V1CrossValidation-results.stats/opt/ADL_db/Users/mkhalil/code/V1CrossValidation-results.stats

  2. /opt/ADL_db/Users/mkhalil/runtime-ImageDB/DB1/db.xml/opt/ADL_db/Users/mkhalil/code/db.xml

  3. 使用输出创建一个新的xml文件。

1 个答案:

答案 0 :(得分:0)

sed -e 's/\/opt\/ADL_db\/Users\/mkhalil\/CshellTest\/ScriptTests\/temp\/V1CrossValidation-results.stats/\/opt\/ADL_db\/Users\/mkhalil\/code\/V1CrossValidation-results.stat‌​s/g' \
-e 's/\/opt\/ADL_db\/Users\/mkhalil\/runtime-ImageDB\/DB1\/db.xml/\/opt\/ADL_db\/Users\/mkhalil\/code\/db.xml/g' input.xml >new.xml