Perl日志处理小贴士

Perl日志处理

Perl能够使你成为Doolittle,不过是通过日志与系统交流。

  1. 读取日志文件
#!/usr/bin/perl -w
 
$logfile="log/secure";
open LOG, "<", "$logfile" or die "Unable to open $logfile: $!\n";
while(<LOG>){
    print if /\bAccepted\b/i;
}
close LOG;
  1. 命令行读取日志文件
perl -ne 'print if /\bsession\b/i' log/secure
选项-n
assume "while (<>) { ... }" loop around program

perl -ne 'print $1."\n" if /\s+(\d+\.\d+\.\d+\.\d+)\s+/' node2-190810.log
  1. 快速比较两个列表
if("@array1[1..20]" ne "@array2"){
	...
}

Perl可以自动将两个列表@array1和@array2转换成字符串(在列表元素间加入空格作为分割符,即join(’ ', @array1[1…20])),然后再对两个结果字符串进行比较。对于高级应用可以使用Array::Compare模块。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值