系统相关
首页 > 系统相关> > 【Linux命令】grep命令

【Linux命令】grep命令

作者:互联网

# n: 显示搜索关键字在文章中第几行
grep -n '1987-10-10' 2.txt

# c: 显示匹配到的个数
grep -c '1987' 2.txt

# A: 显示匹配到关键字下面几行
grep -A 2 '1987-10-10' 2.txt 

# B: 显示匹配到关键字上面几行
grep -B 2 '1987-10-10' 2.txt 

# C: 显示匹配到关键字上下几行
grep -C 2 '1987-10-10' 2.txt

# i: 不区分大小写
grep -i 'DiscoveryClient-InstanceInfoReplicator-0' apollo-assembly.log

# l: 显示包含关键字的文件
grep -l 'exception' *.log

# L: 显示不包含关键字的文件
grep -L '孙' *.txt

##### 正则
# `^`表示行首
grep --color '^1993-01' 2.txt

# `$` 表示行尾
grep '17$' 2.txt
# 使用 w 或者 使用`\<`和`\>`来准确匹配关键字
grep -color '\<registration status\>' apollo-assembly.log
grep -color -w 'registration status' apollo-assembly.log

标签:10,grep,log,命令,关键字,Linux,txt,1987
来源: https://www.cnblogs.com/wchw2008/p/15527996.html