grep搜寻指令

grep搜索指令

GREP常用指令

序号 指令 内容
1 grep 'abc' text.log 包含‘abc’,区分大小写
2 grep -i 'abc' text.log 包含‘abc’,不区分大小写
3 grep -w 'abc' text.log 精确搜索‘abc’单词,区分大小写
4 grep -wi text.log 精确搜索‘abc’单词,不区分大小写
5 grep '^a' text.log 以‘a’开头的内容
6 grep -n 'abc' text.log 搜索结果前展示行号
7 grep '[^a]bc' text.log 搜索bc前没有a的结果
8 grep '^[abc]' text.log 搜索以a或b或c开头的行
9 grep '^abc' text.log 搜索以abc开头的行
10 grep '\.$' text.log 搜索以‘.’结尾的行
11 grep 'abc$' text.log 搜索以‘abc’结尾的行
12 grep -A5 'abc' text.log 包含‘abc’的后5行内容
13 grep -B5 'abc' text.log 包含‘abc’的前5行内容
14 grep -5 'abc' text.log 包含‘abc’的前后5行内容
15 grep '2017-08-30 14:34:3[0-9]' text.log 搜索30秒到39秒之间的报文