[Omaha.pm] Grab all of a specific node out of huge XML files

Jay Hannah jay at jays.net
Wed Sep 12 13:44:20 PDT 2007


Wow. Perl rocks.

j


Problem:

Given a bunch of humongous XML files called pay*, grab all the <RatePlan> 
tags.


Solution:

$ perl -lne '/(<RatePlan .*?>)/ && print $1' pay* | head
<RatePlan RatePlanID="BAR" EffectiveDate="2008-01-05" ExpireDate="2008-01-07">
<RatePlan RatePlanID="BAR" EffectiveDate="2008-01-05" ExpireDate="2008-01-07">
<RatePlan RatePlanID="BAR" EffectiveDate="2008-01-05" ExpireDate="2008-01-07">
<RatePlan RatePlanID="BAR" EffectiveDate="2008-12-20" ExpireDate="2008-12-21">
<RatePlan RatePlanID="BAR" EffectiveDate="2007-12-20" ExpireDate="2007-12-21">
<RatePlan RatePlanID="BAR" EffectiveDate="2007-12-20" ExpireDate="2007-12-21">
<RatePlan RatePlanCode="GCORP">
<RatePlan RatePlanCode="GCORP">
<RatePlan RatePlanCode="GCORP">
<RatePlan RatePlanCode="GCORP">


(You might need to add /m for multi-line matching in case your files 
wrap.)




More information about the Omaha-pm mailing list