|Perl Monk, Perl Meditation|
split file on blank lines and match blocksby raggmopp (Novice)
|on Sep 09, 2012 at 02:43 UTC||Need Help??|
raggmopp has asked for the
wisdom of the Perl Monks concerning the following question:
Hi all. Working with perl 5.8.8 installed on OEL 5.
I am trying to parse a Nagios formatted hosts.cfg file. Each host is separated from the other with a blank line so there is a block related to each host. Each host is also defined with the hostgroups it is a member of.
I am having a hard time trying to figure out what I am missing and the worse part is I'm sober.
A snippet of the data
I have been trying and trying to identify hosts that are members of the CRIT hostgroup, or of the DMZ hostgroup, or the ... The best I have come up with is to print the line that matches. But I'm looking for the host_name and address in addition to the line.
One of my latest attempts
I've tried with grep and regex, no joy. What is it I'm missing?