gpt4 book ai didi

linux - 没有。为一个日期范围打印的行数

转载 作者:太空狗 更新时间:2023-10-29 12:11:43 24 4
gpt4 key购买 nike

我正在尝试计算否。在给定日期范围内打印的行数。

这是我的输入和输出:

grep -inr "\[HSM \]Handle Identity Request. Send Identity Response. timeout: 1550s" *ActNac*
ActNacd.txt:47:2017-01-02 09:10:13 - [HSM ]Handle Identity Request. Send Identity Response. timeout: 1550s
old_ActNacd_2016-12-20_20-39-18.txt:171:2016-12-19 13:23:48 - [HSM ]Handle Identity Request. Send Identity Response. timeout: 1550s
old_ActNacd_2016-12-20_20-39-18.txt:217:2016-12-19 14:27:26 - [HSM ]Handle Identity Request. Send Identity Response. timeout: 1550s
old_ActNacd_2016-12-26_09-44-47.txt:47:2016-12-25 19:26:13 - [HSM ]Handle Identity Request. Send Identity Response. timeout: 1550s
old_ActNacd_2016-12-26_09-44-47.txt:91:2016-12-25 20:30:38 - [HSM ]Handle Identity Request. Send Identity Response. timeout: 1550s
old_ActNacd_2016-12-27_07-32-25.txt:47:2016-12-26 11:08:28 - [HSM ]Handle Identity Request. Send Identity Response. timeout: 1550s
old_ActNacd_2016-12-27_18-06-29.txt:47:2016-12-27 07:35:55 - [HSM ]Handle Identity Request. Send Identity Response. timeout: 1550s
old_ActNacd_2016-12-30_08-22-16.txt:48:2016-12-28 18:04:19 - [HSM ]Handle Identity Request. Send Identity Response. timeout: 1550s
old_ActNacd_2017-01-02_06-56-52.txt:47:2016-12-30 08:24:19 - [HSM ]Handle Identity Request. Send Identity Response. timeout: 1550s
old_ActNacd_2017-01-02_09-07-23.txt:47:2017-01-02 06:59:33 - [HSM ]Handle Identity Request. Send Identity Response. timeout: 1550s

我想找到号码。从日期 2017-12-20 到 2017-12-30 打印的行数。

开始日期和结束日期未确认,所以如果我使用像

这样的 sed 命令
grep -inr "\[HSM \]Handle Identity Request. Send Identity Response. timeout: 1550s" *ActNac* | sed -n '/2016-12-20/,/2017-12-27/p'"

但如果我提供如下输入:

grep -inr "\[HSM \]Handle Identity Request. Send Identity Response. timeout: 1550s" *ActNac* | sed -n '/2016-12-19/,/2017-12-27/p'"

它不提供任何输出,因为开始日期与作为输入日期的任何行都不匹配。没有日期为 2016-12-19 的日志文件。

是否有任何其他方法可以使用 sed/awk/grep 命令获取输入日期范围内的行数。

最佳答案

为此,您可以单独使用 awk

单独计算,

awk -F'[: ]' '$3 >= "2016-12-16" && $3 <= "2016-12-26 && NR>1"{count++;}END{print count}' newfile
5

为了获取实际日志,我使用了日志中实际不存在的日期,

awk -F'[: ]' '$3 >= "2016-12-22" && $3 <= "2016-12-29" && NR>1' newfile
old_ActNacd_2016-12-26_09-44-47.txt:47:2016-12-25 19:26:13 - [HSM ]Handle Identity Request. Send Identity Response. timeout: 1550s
old_ActNacd_2016-12-26_09-44-47.txt:91:2016-12-25 20:30:38 - [HSM ]Handle Identity Request. Send Identity Response. timeout: 1550s
old_ActNacd_2016-12-27_07-32-25.txt:47:2016-12-26 11:08:28 - [HSM ]Handle Identity Request. Send Identity Response. timeout: 1550s
old_ActNacd_2016-12-27_18-06-29.txt:47:2016-12-27 07:35:55 - [HSM ]Handle Identity Request. Send Identity Response. timeout: 1550s
old_ActNacd_2016-12-30_08-22-16.txt:48:2016-12-28 18:04:19 - [HSM ]Handle Identity Request. Send Identity Response. timeout: 1550s

要获取计数,请像在第一个命令中一样使用 {count++;}END{print count} 子句。

关于linux - 没有。为一个日期范围打印的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41427975/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com