2017-04-25 5 views
1

私はこれを使用してXMLファイルを編集するxmlstarletを使用するスクリプトがあります。問題があることであるしかしXML - XMLファイル内の値を検索する

<configuration> 
    .... 
    .... 
    .... 
    <property> 
     <name>this.is.a.node</name> 
     <value>value.for.above.node</value> 
     </property> 
     <property> 
     <name>this.is.another.node</name> 
     <value>value.for.second</value> 
     </property> 
    </configuration> 

sudo xmlstarlet ed -L --omit-decl \ 
-s '//configuration' -t elem -n "property" -v '' \ 
-s '//configuration/property[last()]' -t elem -n "name" -v "this.is.a.node" \ 
-s '//configuration/property[last()]' -t elem -n "value" -v "value.for.above.node" \ 
-s '//configuration' -t elem -n "property" -v '' \ 
-s '//configuration/property[last()]' -t elem -n "name" -v "this.is.another.node" \ 
-s '//configuration/property[last()]' -t elem -n "value" -v "value.for.second" \ 
/path/to/file 

この、その結果スクリプトが複数回実行されている場合は、上記のブロックが再度追加されます。私はそれを避けたいですが、私はそれについてどうやって行くのか分かりません。私は条件文

答えて

2

使用count

if [[ $(xmlstarlet sel -t -v "count(/configuration/property[name='this.is.a.node'])" /paht/to/file/xml) -eq 1 ]];then echo "there"; else echo "nope"; fi 
+0

作品をサポートマニュアルの何かを見つける傾けます!どうもありがとう – Beginner

関連する問題