파일 이름이 첨부된 특정 시간 사이의 모든 줄을 추출하고 싶습니다.
입력 예:
Dec 8 22:00:05 host kernel:
Dec 8 23:00:05 host kernel:
Dec 8 23:34:45 host kernel:
Dec 8 23:54:45 host kernel:
Dec 9 00:34:45 host kernel:
Dec 9 00:54:45 host kernel:
Dec 9 01:54:45 host kernel:
Dec 9 02:54:45 host kernel:
Dec 9 03:54:45 host kernel:
Dec 9 04:54:45 host kernel:
Dec 9 05:54:45 host kernel:
내가 원하는 출력:
Dec 8 23:00:05 host kernel:
Dec 8 23:34:45 host kernel:
Dec 8 23:54:45 host kernel:
Dec 9 00:34:45 host kernel:
Dec 9 00:54:45 host kernel:
답변1
어때요?밀러?
$ mlr --nidx --repifs filter -S '
t = strptime($3,"%H:%M:%S");
t > strptime("23:00","%H:%M") || t < strptime("01:00","%H:%M")
' input
Dec 8 23:00:05 hermes kernel: [<ffffffff8118a6f0>] warn_alloc_failed+0x110/0x180
Dec 8 23:34:45 hermes kernel: [<ffffffff816a204a>] __alloc_pages_slowpath+0x6b6/0x724
Dec 8 23:54:45 hermes kernel: [<ffffffff81424400>] ? misc_open+0x40/0x1c0
Dec 9 00:34:45 hermes kernel: [<ffffffff8118ec85>] __alloc_pages_nodemask+0x405/0x420
Dec 9 00:54:45 hermes kernel: [<ffffffff8118ec85>] __alloc_pages_nodemask+0x405/0x420
답변2
올바르게 이해했다면 GNU를 사용하십시오 grep
.
grep -e "00:[0-5][0-9]:[0-5][0-9]" -e "23:[0-5][0-9]:[0-5][0-9]" in_file > out_file
패턴을 찾고 있어요00:[<0 to five><0 to nine>]:[<0 to five><0 to nine>]
또는 패턴23:[<0 to five><0 to nine>]:[<0 to five><0 to nine>]
답변3
Perl의 경우 12월 8일 오후 11시에 시작하여 2시간 연장한다고 가정해 보겠습니다.
perl -MTime::Piece -lane '
BEGIN {
$start = Time::Piece->strptime("Dec 8 23:00:00", "%b %d %T");
$stop = $start + 2*3600;
}
$t = Time::Piece->strptime("@F[0,1,2]", "%b %d %T");
print if $start <= $t && $t <= $stop;
' file