分割日志并排序关键字
#!/usr/bin/perl -w
use strict;
my $path="/home/zengkaibin/myperl/filter.log";
my $result1="/home/zengkaibin/logs/sq.log";
my $result2="/home/zengkaibin/logs/usr.log";
my %hashusr;
my %hashsq;
open(FS,"$path")||die "ERROR:cann't open $path:$!";
while(){
if(/\A.*(86\d\d\d\d\d\d\d\d\d\d\d).*HIT_B:(.*)MSG.*\Z/){
chomp;
my $usr=$1;
my $sq=$2;
$hashusr{$usr}++;
$hashsq{$sq}++;
}
}
open (OUT,">>$result1")||die "ERROR:cann't open $result1:$!";
foreach(sort {$hashsq{$b} <=> $hashsq{$a}} keys %hashsq){
my $ges1=sprintf("%10d",$hashsq{$_});
print OUT "$ges1| $_ \n";
}
open (OUTT,">>$result2")||die "ERROR:cann't open $result2:$!";
foreach(sort {$hashusr{$b} <=> $hashusr{$a}} keys %hashusr){
my $ges2=sprintf("%10d",$hashusr{$_});
print OUTT "$ges2| $_ \n";
}
close(FS);
close(OUT);
close(OUTT);
阅读(1215) | 评论(0) | 转发(0) |