gpt4 book ai didi

linux - 从 unix 或 linux 中的系统日期中提取 txt 文件中存在的键值计数

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:32:24 25 4
gpt4 key购买 nike

下面的文件每天生成工作计数键值。我需要从当前日期提取具体计数。请帮帮我。

工作计数.txt

Sun Jul 13 01:00:01 PDT 2014
Mon Jul 14 01:00:02 PDT 2014
4d972230-0b5a-11e4-a900-0ed3c9c5b6a3
23d41150-0b74-11e4-49ac-be7a81b06437
1c4a6cc0-0b7b-11e4-258d-1ee0158edd78
85bf5e10-0b83-11e4-716f-4253342907af
8610b260-0b83-11e4-49ac-be7a81b06437
ecf70dc0-0b84-11e4-c558-b6711cc279a6
d569cca0-0b99-11e4-8d77-f2b426de171e
Tue Jul 15 01:00:01 PDT 2014
92e85260-0c30-11e4-258d-1ee0158edd78
bdf103d0-0c30-11e4-c558-b6711cc279a6
343cf3c0-0c34-11e4-c94d-fa2a5e818fe8
34723490-0c34-11e4-c558-b6711cc279a6
3497e500-0c34-11e4-258d-1ee0158edd78
66711ad0-0c46-11e4-49ac-be7a81b06437
66dd4a20-0c46-11e4-258d-1ee0158edd78
87a28070-0c48-11e4-a900-0ed3c9c5b6a3
f19ea750-0c49-11e4-c558-b6711cc279a6
Wed Jul 16 01:00:01 PDT 2014
426ede80-0cdf-11e4-716f-4253342907af
17a1a3e0-0ce9-11e4-49ac-be7a81b06437
1797dfe0-0ce9-11e4-c558-b6711cc279a6
176d2660-0ce9-11e4-258d-1ee0158edd78
17882870-0ce9-11e4-c94d-fa2a5e818fe8
173ca080-0ce9-11e4-dd2f-0ed3c9c5b6a3
179fcf20-0ce9-11e4-716f-4253342907af
7ebbc300-0cf6-11e4-c94d-fa2a5e818fe8
26d21980-0cfd-11e4-49ac-be7a81b06437
Thu Jul 17 01:00:01 PDT 2014
e9cf91d0-0daf-11e4-49ac-be7a81b06437
ea7d0fe0-0daf-11e4-258d-1ee0158edd78
eb50b390-0daf-11e4-716f-4253342907af
5284fa50-0dd1-11e4-dd2f-0ed3c9c5b6a3

假设 Thu Jul 17 1:05:34 PDT 2014 是当前系统日期,我需要提取当前日期的计数,如下所示:

We had 4 connection reset work unit failures today. 

最佳答案

awk -v d="$(date)" 'BEGIN { c = 0; sub(/..:..:../, "..:..:..", d); d = "^" d "$" } { sub(/[ \t\r]*$/, "") } /^[A-Z][a-z][a-z] / { if (p) exit; if ($0 ~ d)p = 1; next } NF && p { ++c } END { print "We have " c " connection reset workunit failures for that day." }' your_file

输出:

We have 4 connection reset workunit failures for that day.

如果您确实需要添加成对的**,只需修改print 命令即可。

调试版本:

#!/usr/bin/awk -f
BEGIN {
stderr = "/dev/stderr"
counter = 0
sub(/..:..:../, "..:..:..", date)
date = "^" date "$"
printf("Date pattern: %s\n", date) > stderr
}
{
sub(/[ \t\r]*$/, "")
}
/^[A-Z][a-z][a-z] / {
if (p) {
printf("Found second date line: %s. Exiting.\n", $0) > stderr
exit
}
if ($0 ~ date) {
printf("Found date line: %s\n", $0) > stderr
p = 1
}
next
}
NF && p {
printf("Increasing counter for line: %s\n", $0) > stderr
++counter
}
END {
print "We have " counter " connection reset workunit failures for that day."
}

用法:

awk -v date="$(date)" -f script.awk your_file

关于linux - 从 unix 或 linux 中的系统日期中提取 txt 文件中存在的键值计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24819203/

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