请教这个shell的写法,统计行数
2009-07-04 14:00
183 查看
CU shell版备案参考我的日志格式为:
09:55:54: ERROR1 /tmp/error/log.3 50 times
09:56:09: ERROR1 /tmp/error/log.14 50 times
10:56:12: ERROR1 /tmp/error/log.14 100 times
10:56:23: ERROR2 /tmp/error/log.5 50 times
11:56:26: ERROR2 /tmp/error/log.1 50 times
11:56:27: ERROR2 /tmp/error/log.5 100 times
15:56:29: ERROR3 /tmp/error/log.1 100 times
15:56:32: ERROR3 /tmp/error/log.1 150 times
16:56:33: ERROR4 /tmp/error/log.6 50 times
16:56:36: ERROR4 /tmp/error/log.6 100 times
16:56:40: ERROR4 /tmp/error/log.12 50 times
我想统计某时段某种类型的告警次数,时段取第一列第一个:之前的字符,告警类型取第二列,值不定,后面的字符可以不管。我想输出结果为:
09时ERROR1告警为2条。
10时ERROR1告警为1条。
10时ERROR2告警为1条。
11时ERROR2告警为2条。
15时ERROR3告警为2条。
16时ERROR4告警为3条。 Answer awk -F'[: ]+' '{a[$1"时"$4]++}END{for(i in a)print i"告警为"a[i]"条."}' ufile
09:55:54: ERROR1 /tmp/error/log.3 50 times
09:56:09: ERROR1 /tmp/error/log.14 50 times
10:56:12: ERROR1 /tmp/error/log.14 100 times
10:56:23: ERROR2 /tmp/error/log.5 50 times
11:56:26: ERROR2 /tmp/error/log.1 50 times
11:56:27: ERROR2 /tmp/error/log.5 100 times
15:56:29: ERROR3 /tmp/error/log.1 100 times
15:56:32: ERROR3 /tmp/error/log.1 150 times
16:56:33: ERROR4 /tmp/error/log.6 50 times
16:56:36: ERROR4 /tmp/error/log.6 100 times
16:56:40: ERROR4 /tmp/error/log.12 50 times
我想统计某时段某种类型的告警次数,时段取第一列第一个:之前的字符,告警类型取第二列,值不定,后面的字符可以不管。我想输出结果为:
09时ERROR1告警为2条。
10时ERROR1告警为1条。
10时ERROR2告警为1条。
11时ERROR2告警为2条。
15时ERROR3告警为2条。
16时ERROR4告警为3条。 Answer awk -F'[: ]+' '{a[$1"时"$4]++}END{for(i in a)print i"告警为"a[i]"条."}' ufile
相关文章推荐
- Shell脚本实现C语言代码行数统计
- shell命令统计文件内容行数和行首地址
- Shell统计代码行数
- Linux下统计某个目录下所有源代码行数的Shell脚本
- shell统计文件夹代码行数
- 一行shell命令统计代码行数
- Linux下统计某个目录下所有源代码行数的Shell脚本;
- 统计python脚本中 shell命令输出文本的行数
- 采用shell脚本统计代码的行数
- shell统计代码行数
- Shell脚本实现C语言代码行数统计
- Linux下统计某个目录下所有源代码行数的Shell脚本
- 一句shell命令搞定代码行数统计
- Shell脚本统计文件行数的8种方法
- shell如何统计文本文件行数
- shell 命令统计代码行数的简单代码
- 一句shell命令搞定代码行数统计
- Shell统计代码行数
- shell 统计某个文件的行数命令
- shell实现代码行数统计