【发布时间】:2015-06-01 21:08:45
【问题描述】:
我有以下 perl 脚本。
#!/usr/bin/perl -w
use strict;
use warnings;
my (@failhost);
my %currblocked;
my %addblocked;
my $action;
open (MYINPUTFILE, "/var/log/asterisk/messages") or die "\n", $!, "Does log file file exist\?\n\n";
while (<MYINPUTFILE>) {
my ($line) = $_;
chomp($line);
if ($line =~ m/\' failed for \'(.*?)\' - No matching peer found/) {
push(@failhost,$1);
}
if ($line =~ m/\' failed for \'(.*?)\' . Wrong password/) {
push(@failhost,$1);
print $1 . "\n";
}
}
exit 0;
这会产生以下结果。
212.83.134.244:5065
212.83.134.244:5063
212.83.134.244:5092
212.83.134.244:5109
212.83.134.244:5080
212.83.134.244:5110
212.83.134.244:5096
212.83.134.244:5093
212.83.134.244:5089
212.83.134.244:5073
212.83.134.244:5101
212.83.134.244:5072
212.83.134.244:5092
212.83.134.244:5094
212.83.134.244:5076
212.83.134.244:5080
212.83.134.244:5081
212.83.134.244:5094
212.83.134.244:5077
212.83.134.244:5096
212.83.134.244:5069
212.83.134.244:5097
212.83.134.244:5101
我想删除包括“:”在内的所有端口号,只想保留IP地址。
想要的结果是这样的
212.83.134.244
212.83.134.244
212.83.134.244
212.83.134.244
212.83.134.244
212.83.134.244
212.83.134.244
212.83.134.244
212.83.134.244
212.83.134.244
212.83.134.244
如果有人可以指导我,或者告诉我如何做到这一点,我将不胜感激?
提前致谢。
【问题讨论】: