Skip to content

log分析技巧grep

实时监控关键字

shell
tail -f text.log | grep "关键字"
tail -f text.log | grep "关键字"

查询日志的关键字

shell
grep "xxx"  --color text.log
grep "xxx"  --color text.log

grep遍历文件夹查找文件

bash
grep -r "要查找的内容" ./
grep -r "要查找的内容" ./

前后几行

grep -C 5 foo file 显示file文件里匹配foo字串那行以及上下5行
grep -B 5 foo file 显示foo及前5行
grep -A 5 foo file 显示foo及后5行

结合一下: 查看关键字上下五行数据

bash
grep  -B 5  "关键字xxx"  --color yourfile.log
grep  -B 5  "关键字xxx"  --color yourfile.log

(36条消息) Grep命令查找多个字符串(grep同时匹配多个关键字或任意关键字)_普通网友的博客-CSDN博客_grep 多个字段

grep word1 file.txt | grep word2 |grep word3
grep word1 file.txt | grep word2 |grep word3
bash
zcat xx.log.2022-10-27.* | grep itemKey:903300
zcat xx.log.2022-10-27.* | grep itemKey:903300