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 $_; } }
In reply to how to remove matched multi lines by cxfcxf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |