[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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




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.)