grep命令学习

grep  过滤出指定的行
grep ‘root‘ /etc/passwd  过滤root字符的行
grep --color -n ’root‘  /etc/passwd   深色字符显示匹配项
grep --color -nv ’root‘  /etc/passwd   显示没有root字符匹配项
grep --color -n -A 2 'root' 1.txt  匹配并显示下面2行
grep --color -n -B 2 'root' 1.txt   匹配并显示上面2行
grep --color -n -C 2 'root' 1.txt   匹配并显示上下各2行
grep --color -r 'iptables' /etc/*   遍历目录查找有iptables的文件的行
grep --color -rh 'iptables' /etc/*   遍历目录查找有iptables的文件的行(只显示结果,不要文件目录)
gr '[a-zA-Z]' 1.txt   匹配包含字母的行
gr -v '[a-zA-Z]' 1.txt   匹配不包含字母的行gr  '^[a-z]' 1.txt    匹配以字母开头的行
gr  -v '^[a-z]' 1.txt    匹配不以字母开头的行
gr  '^[^0-9]' 1.txt    匹配不以数字开头的行
gr  '^$' 1.txt    匹配空行
gr  -v  '^$'  1.txt  匹配非空行
gr  'r.o' 1.txt  匹配r.o  . 可以匹配任意一个字符
gr  'r*o' 1.txt   匹配一个或者多个中间字符
gr  'r.*o' 1.txt    匹配r开头 o 结尾的字符

gr  'r\?o' 1.txt    0或者1个? 前面的字符  故此可以匹配  o  或 ro

egrep --color 'root|nologin' 1.txt   或者匹配项
grep  'root' 1.txt |grep 'nologin'  匹配并且项
egrep  --color '(rr)+'  1.txt   匹配整体  rr无限次数
egrep --color '(rr){1,3}' 1.txt    匹配1-3次rr的行
egrep --color '(rr){5}' 1.txt    匹配5次rr的行
egrep  --color 'r+o' 1.txt  匹配一个或多个r   

\  脱意字符

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值