ShellScriptド素人メモ
xmllintを使って以下のxmlを解析して値&属性値を取り出す
sample.xml
<?xml version='1.0' encoding='utf-8' ?>
<top>
<int name="hoge" value="327">100</int>
</top>
属性値を出力
327を取り出す場合、以下のようにする
echo 'cat /top/int/@value' | xmllint --shell sample.xml | grep value= | sed 's/[^"]*"\([^"]*\)"[^"]*/\1/g'
要素の内容を取得
100を取り出す場合、以下のようにする
echo 'cat /top/int' | xmllint --shell sample.xml | grep value= | sed 's/^.*<int.*>\(.*\)<\/int>.*$/\1/'