cxfcxf has asked for the wisdom of the Perl Monks concerning the following question:
this is the file. i want to remove the whole block likedefine host{ use windows-server host_name serverA hostgroups 060202 alias 060202 contact_groups yu address 192.168.1.1 } define host{ use windows-server host_name serverA hostgroups 060202 alias 060202 contact_groups yu address 192.168.1.11 } define host{ use windows-server host_name serverA hostgroups 060202 alias 060202 contact_groups yu address 192.168.1.21 } define host{ use windows-server host_name serverA hostgroups 060202 alias 060202 contact_groups yu address 192.168.1.1 }
so i wrote a scripts likedefine host{ use windows-server host_name serverA hostgroups 060202 alias 060202 contact_groups yu address 192.168.1.1 }
it just print one line which matchs 192.168.1.1.... so i recognized $_ in while (<NAG>) is just a line... i cant use range operator here... are there any way to reach the goal?open(NAG,"nagios") or dir $!; my $start = qr/^define/; my $end = qr/^\}$/; my @array; while (<NAG>) { if (/$start/ .. /$end/) { push @array, $_; } } foreach (@array) { if (/192.168.1.1/) { print $_; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to remove matched multi lines
by jwkrahn (Abbot) on Jul 25, 2009 at 02:30 UTC | |
|
Re: how to remove matched multi lines
by bichonfrise74 (Vicar) on Jul 25, 2009 at 04:46 UTC | |
|
Re: how to remove matched multi lines
by Marshall (Canon) on Jul 27, 2009 at 23:34 UTC | |
by GrandFather (Saint) on Jul 28, 2009 at 20:51 UTC |