使用perl在xxx.log文件中找到fail单词
1 #!/usr/bin/perl -w 2 ##Copyright (C) 2020 by WangZhe 3 4 use autodie; 5 open my $log_fh,'<','xxx.log'; 6 $match = 0; 7 while(<$log_fh>){ 8 chomp; 9 while(/fail/g){ 10 $match ++;} 11 } 12 if($match == 0){ 13 print("No match");} 14 else{ 15 print("Matched $match times in total\n");} 16
xxx.log文件内容:
打印结果: 
更改xxx.log文件内容:
打印结果:
若不存在xxx.log文件,打印结果:
博客园:will_w
觉得有用就点个赞吧!~

浙公网安备 33010602011771号