- 论坛徽章:
- 307
|
本帖最后由 sunzhiguolu 于 2017-03-04 17:05 编辑
回复 5# gtluck
cat a.txt
------------------------
now:1488448457
dog data
name = bbbb
birthday = 20151201 14:23:23
gender=male
healthy = nok
dog data
name = bbbb
birthday = 20151201 14:23:23
gender=male
healthy = nok
dog data
name = cccc
birthday = 20151202 15:23:23
gender=male
healthy = nok
- #!/usr/bin/perl
- use strict;
- use warnings;
- use Time::Local;
- use Time::Seconds;
- foreach my $path (glob ('urPath:\\*.txt')){
- open (my $FHr, '<', $path);
- my $now = $1 if (<$FHr> =~ /(\d+)/);
- local $/ = '';
- while (<$FHr>){
- my @aItems = (split ("\n", $_))[1, 2, -1];
- next if ($aItems[0] =~ /(\S+)\z/ and $1 ne 'bbbb');
- next if ($aItems[-1] =~ /(\S+)\z/ and $1 eq 'nok');
- my @aTimes = $aItems[1] =~ /(\d{4})(\d{2})(\d{2})\s+(\d+):(\d+):(\d+)/;
- $aTimes[1] -= 1;
- my $time = timegm (reverse (@aTimes));
- next if (Time::Seconds->new ($now - $time)->hours <= 10);
- print $path, "\n";
- last;
- }
- close ($FHr);
- }
复制代码
|
|