[olug] Cheesy XML wrangling

Jay Hannah jay at jays.net
Sat Mar 1 16:16:51 UTC 2008


I've been doing a lot of cheesy XML parsing w/ command-line perl  
lately. Perl is great at elegant XML handling too (I'm a fan of  
XML::Twig), but it's hard to beat 30-second command line solutions to  
answer simple questions...

Linux + GNU + Perl is awesome.   :)

j
preaching to the choir


$ head -3 RevData.DALMAN.20080301.xml
<revolutiondata asof="20080301091702" hotel="DALMAN" seq="20080301"  
ver="1.5">
   <reservations>
     <res actrrev="972" bktime="20070915050836" cas="N"  
doa="20071027" evt="notevent" exprrev="972" gcnt="1"  
grp="13700106165" gtd="Y" id="2009477241" inlos="6"  
intime="20071027100400" los="6" off="notoffer"  
outtime="20071102041200" rcnt="1" rt="DELUXE" seg="06" src="WB"  
st="R" time="20080301091703" xltime=""/>

$ grep '<res ' RevData.DALMAN.20080301.xml | perl -nle '/rt="(.*?)"/;  
print $1' | sort | uniq -c
   50699 DELUXE
   16144 SUITES
    1180 UMAN




More information about the OLUG mailing list