Thursday 15 October 2009

extact attributes out of an xml section

I have the following xml section, I want to extract only attributes i.e values enclosed in " " inside key element. This is how i do,


bash$echo " <key name="extract1">
</key>
<key name="extract2">
</key>
<key name="extract3">
</key>
<key name="extract4">
</key>" | perl -nle '$_ =~ m#.*<key name="(\w+)">.*#s and print $1;'
extract1
extract2
extract3
extract4



No comments:

Post a Comment

Tweets by @sriramperumalla