perl -MXML::Parser -le '$p=XML::Parser->new( Handlers=>{Start=>sub{$k.=".$_[1]";$h{$k}++}, End=>sub{$k=~s/.$_[1]$//;}}); $p->parsefile(shift); END{print "$h{$_}\t$_" for (sort keys %h)}' some_file.xml
(Line-breaks added for legibility; the first time I did this, it really was all on one line -- honest!)
|
|---|