从时间戳列表中获取上午 8 点到下午 5 点之间的时间戳
Get timestamps between 8am to 5pm from timestamps list
我有一个提取日期时间戳的列表。从这个列表中,我想为每个 date/time 打印上午 8 点到下午 5 点之间的时间戳。但是我下面的代码没有产生任何输出。
数据:
2021-Sep-16 21:24:48
2021-Sep-17 03:31:05
2021-Sep-17 08:30:23
2021-Sep-17 09:42:43
2021-Sep-17 12:43:14
2021-Sep-17 14:43:23
2021-Sep-17 15:50:34
2021-Sep-17 16:50:35
2021-Sep-18 03:31:05
2021-Sep-18 08:30:23
2021-Sep-18 09:42:43
2021-Sep-18 12:43:14
2021-Sep-18 14:43:23
2021-Sep-18 15:50:34
2021-Sep-18 22:50:35
预期输出:
2021-Sep-17 08:30:23
2021-Sep-17 09:42:43
2021-Sep-17 12:43:14
2021-Sep-17 14:43:23
2021-Sep-18 08:30:23
2021-Sep-18 09:42:43
2021-Sep-18 12:43:14
2021-Sep-18 14:43:23
我的代码:
sub read_timestamps{
my $file = './logs/file.log';
open(IN, "<" ,"$file") or die "Couldn't open file $!";
open(OUT, ">" ,"_trash/tmp/raw/0-out.txt") or die "Couldn't open file $!";
my @content = <IN>;
my $start="08:00:00";
my $end = "17:00:00";
foreach $lines(@content){
if($lines = ~/$start/../$end/){
print OUT (" \n") if($lines =~ /(\d{4}-\w+-\d{2} \d\d:\d\d:\d\d)/);
}
}
}
while (<>) {
my ( $h ) = / (\d+)/
or next;
print if $h >= 8 && $h < 17;
}
我有一个提取日期时间戳的列表。从这个列表中,我想为每个 date/time 打印上午 8 点到下午 5 点之间的时间戳。但是我下面的代码没有产生任何输出。
数据:
2021-Sep-16 21:24:48
2021-Sep-17 03:31:05
2021-Sep-17 08:30:23
2021-Sep-17 09:42:43
2021-Sep-17 12:43:14
2021-Sep-17 14:43:23
2021-Sep-17 15:50:34
2021-Sep-17 16:50:35
2021-Sep-18 03:31:05
2021-Sep-18 08:30:23
2021-Sep-18 09:42:43
2021-Sep-18 12:43:14
2021-Sep-18 14:43:23
2021-Sep-18 15:50:34
2021-Sep-18 22:50:35
预期输出:
2021-Sep-17 08:30:23
2021-Sep-17 09:42:43
2021-Sep-17 12:43:14
2021-Sep-17 14:43:23
2021-Sep-18 08:30:23
2021-Sep-18 09:42:43
2021-Sep-18 12:43:14
2021-Sep-18 14:43:23
我的代码:
sub read_timestamps{
my $file = './logs/file.log';
open(IN, "<" ,"$file") or die "Couldn't open file $!";
open(OUT, ">" ,"_trash/tmp/raw/0-out.txt") or die "Couldn't open file $!";
my @content = <IN>;
my $start="08:00:00";
my $end = "17:00:00";
foreach $lines(@content){
if($lines = ~/$start/../$end/){
print OUT (" \n") if($lines =~ /(\d{4}-\w+-\d{2} \d\d:\d\d:\d\d)/);
}
}
}
while (<>) {
my ( $h ) = / (\d+)/
or next;
print if $h >= 8 && $h < 17;
}