分割日志并排序关键字的perl脚本,有需要的朋友可以参考下。
#!/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(<FS>){
if(/A.*(86ddddddddddd).*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);