[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Omaha.pm] Count occurrences of the value of an attribute in XML
Better yet, skip the lines that don't contain rt="" at all.
$ perl -lne '/rt="(\w+)"/ && print $1' RevData.DALMAN.20070529.xml |
uniq -c
117 DELUXE
84 SUITES
j
-----Original Message-----
From: Jay Hannah
Sent: Tuesday, May 29, 2007 7:39 PM
To: 'omaha-pm@pm.org'
Subject: Count occurrences of the value of an attribute in XML
Problem: Given data like this:
$ head RevData.DALMAN.20070529.xml
<revolutiondata asof="20070529192916" hotel="DALMAN" seq="20070529"
ver="1.50">
<rates>
<rate end="20070530" rt="DELUXE" seg="01" start="20070529">
<minmax gcnt="1" max="315.00" min="315.00"/>
<minmax gcnt="2" max="315.00" min="315.00"/>
<minmax gcnt="3" max="325.00" min="325.00"/>
</rate>
<rate end="20070604" rt="DELUXE" seg="01" start="20070531">
<minmax gcnt="1" max="305.00" min="305.00"/>
<minmax gcnt="2" max="305.00" min="305.00"/>
Count the number of each occurence of the attribute 'rt'.
Solution:
$ perl -lne '/rt="(\w+)"/; print $1' RevData.DALMAN.20070529.xml | uniq
-c
2
585 DELUXE
422 SUITES
j