去除nagios.cfg里所有的空行和以#开头的行
[root@trffic root]# cat perl.sh
#!/usr/bin/perl
open (CFG,"/usr/local/nagios/etc/nagios.cfg") or die "Can't open file! $!";
while () {
if(!/^\s+$/){
if($_ !~/^#/){
print $_;
}
}
}
close (CFG);
改进:
[root@trffic root]# cat perl2.sh
#!/usr/bin/perl
open (CFG,"/usr/local/nagios/etc/nagios.cfg") or die "Can't open file! $!";
while () {
if(!/^\s+$/ and !/^#/){
print $_;
}
}
close (CFG);
阅读(982) | 评论(0) | 转发(0) |