Perl 懒惰匹配
来源:互联网 发布:windows nginx 下载 编辑:程序博客网 时间:2024/04/30 22:39
[grid@devrac1 ~]$ cat sum.pl
if ( $#ARGV < 0 ){
print "please input your file!\n";
exit(-1);
}
$logfile= $ARGV[0];
my %log;
open (LOG ,"<","$logfile");
while (<LOG>) {
chomp;
if ($_ =~ /^\[\[seri(.*)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/){
print "\$1 is $1\n";
$var= (split /_/, (split /:/,$_)[2])[0];
$log{$var}++;
}
}
#print %log;
while(my($ip, $times) = each %log) {
print "$ip $times\n";
}
[grid@devrac1 ~]$ perl sum.pl 1.log
$1 is :288i19BF:122.96.47.8_se[[seri:288i19BF:12
$1 is :288i19BF:122.96.47.8_se[[seri:288i19BF:12
$1 is :288i19BF:122.96.47.8_se[[seri:288i19BF:12
$1 is :288i19BF:192.96.47.8_se[[seri:288i19BF:19
192.96.47.8 1
122.96.47.8 3
这里直接贪婪的匹配到了:288i19BF:192.96.47.8_se[[seri:288i19BF:19
-----------------------------------------------------------------
[grid@devrac1 ~]$ cat sum.pl
if ( $#ARGV < 0 ){
print "please input your file!\n";
exit(-1);
}
$logfile= $ARGV[0];
my %log;
open (LOG ,"<","$logfile");
while (<LOG>) {
chomp;
if ($_ =~ /^\[\[seri(.*?)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/){
print "\$1 is $1\n";
$var= (split /_/, (split /:/,$_)[2])[0];
$log{$var}++;
}
}
#print %log;
while(my($ip, $times) = each %log) {
print "$ip $times\n";
}
[grid@devrac1 ~]$ perl sum.pl 1.log
$1 is :288i19BF:
$1 is :288i19BF:
$1 is :288i19BF:
$1 is :288i19BF:
192.96.47.8 1
122.96.47.8 3
这里匹配到第一个就停止了
[grid@devrac1 ~]$ cat 1.log
[[seri:288i19BF:122.96.47.8_se[[seri:288i19BF:122.96.47.8ssionid:
[[seri:288i19BF:122.96.47.8_se[[seri:288i19BF:122.96.47.8ssionid:
[[seri:288i19BF:122.96.47.8_se[[seri:288i19BF:122.96.47.8ssionid:
[[seri:288i19BF:192.96.47.8_se[[seri:288i19BF:192.96.47.8ssionid:
if ( $#ARGV < 0 ){
print "please input your file!\n";
exit(-1);
}
$logfile= $ARGV[0];
my %log;
open (LOG ,"<","$logfile");
while (<LOG>) {
chomp;
if ($_ =~ /^\[\[seri(.*)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/){
print "\$1 is $1\n";
$var= (split /_/, (split /:/,$_)[2])[0];
$log{$var}++;
}
}
#print %log;
while(my($ip, $times) = each %log) {
print "$ip $times\n";
}
[grid@devrac1 ~]$ perl sum.pl 1.log
$1 is :288i19BF:122.96.47.8_se[[seri:288i19BF:12
$1 is :288i19BF:122.96.47.8_se[[seri:288i19BF:12
$1 is :288i19BF:122.96.47.8_se[[seri:288i19BF:12
$1 is :288i19BF:192.96.47.8_se[[seri:288i19BF:19
192.96.47.8 1
122.96.47.8 3
这里直接贪婪的匹配到了:288i19BF:192.96.47.8_se[[seri:288i19BF:19
-----------------------------------------------------------------
[grid@devrac1 ~]$ cat sum.pl
if ( $#ARGV < 0 ){
print "please input your file!\n";
exit(-1);
}
$logfile= $ARGV[0];
my %log;
open (LOG ,"<","$logfile");
while (<LOG>) {
chomp;
if ($_ =~ /^\[\[seri(.*?)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/){
print "\$1 is $1\n";
$var= (split /_/, (split /:/,$_)[2])[0];
$log{$var}++;
}
}
#print %log;
while(my($ip, $times) = each %log) {
print "$ip $times\n";
}
[grid@devrac1 ~]$ perl sum.pl 1.log
$1 is :288i19BF:
$1 is :288i19BF:
$1 is :288i19BF:
$1 is :288i19BF:
192.96.47.8 1
122.96.47.8 3
这里匹配到第一个就停止了
[grid@devrac1 ~]$ cat 1.log
[[seri:288i19BF:122.96.47.8_se[[seri:288i19BF:122.96.47.8ssionid:
[[seri:288i19BF:122.96.47.8_se[[seri:288i19BF:122.96.47.8ssionid:
[[seri:288i19BF:122.96.47.8_se[[seri:288i19BF:122.96.47.8ssionid:
[[seri:288i19BF:192.96.47.8_se[[seri:288i19BF:192.96.47.8ssionid:
0 0
- Perl 懒惰匹配
- 懒惰匹配
- Java懒惰匹配
- 正则表达式懒惰匹配
- 正则表达式懒惰匹配,和贪婪匹配
- 正则中的“贪婪匹配”和“懒惰匹配”
- Grep 最短匹配 懒惰匹配
- 正则表达式 懒惰匹配与贪婪匹配
- Java 正则表达式中的懒惰匹配
- PHP正则贪婪/懒惰匹配模式
- 懒惰模式如何匹配所有字符
- 懒惰
- 懒惰!
- 懒惰
- 懒惰。。。
- 懒惰
- (PHP)正则表达式-贪婪匹配与懒惰匹配的区别
- 正则表达式的贪婪匹配与懒惰匹配
- 3D赛瓦号——整装待发!
- 信号量与互斥锁性能对比
- 常用开发工具的密钥收藏
- 线段树总结
- leetcode_25_Reverse Nodes in k-Group
- Perl 懒惰匹配
- SHOI 2014 全
- Problem K: Cylinder
- 我为什么要求你用功读书
- [Android] ListView 滚回顶部
- leetcode_138_ Copy List with Random Pointer
- 数据结构之栈
- HTTP协议与XML
- Xcode提交代码到SVN,文件右边出现UM