[todo]锋利的linux日志分析命令
预处理 从一个文件中过滤 grep key file ➜ grep ERROR a.log 12:12 ERROR:core bad message 从多个文件中过滤 grep key file1 fil2 多文件搜索,指定多个文件 grep key *.log 使用正则的方式,匹配多个文件 grep -h key *.log 可以使用-h, 让结果中不出现文件名。默认文件名会出现在匹配行的前面。 ➜ grep ERROR a.log b.log a.log:12:12 ERROR:core bad message b.log:13:12 ERROR:core bad message ➜ grep ERROR *.log a.log:12:12 ERROR:core bad message b.log:13:12 ERROR:core bad message 多个关键词过滤 grep -e key1 -e key2 file 使用-e参数,可以制定多个关键词 ➜ grep -e ERROR -e INFO a.log 12:12 ERROR:core bad message 12:12 INFO:parse bad message1 正则过滤 grep -E REG file 下面例子是匹配db:后跟数字部分 ➜ grep -E "db:\d+ " a.log 12:14 WARNING:db:1 bad message 12:14 WARNING:db:21 bad message 12:14 WARNING:db:2 bad message1 12:14 WARNING:db:4 bad message 仅输出匹配字段 grep -o args 使用-o参数,可以仅仅输出匹配项,而不是整个匹配的行 ➜ go-tour grep -o -E "db:\d+ " a.log db:1 db:21 db:2 db:4 统计关键词出现的行数 例如一个nginx的access.log, 我们想统计其中的POST的个数,和OPTIONS的个数。 ...