微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

正则表达式

eg:1


grep 'root' /etc/passwd -------------把有root的行过滤出来


grep --color 'root' /etc/passwd ---------------把过滤出来的高亮显示出来



grep -v 'root' /etc/passwd ------------把不包含root的行显示出来




grep --color -A 2 'root' /etc/passwd --------显示过滤的行,把过滤行后面2行也输出


grep --color -n -A 2 'root' /etc/passwd -----------有行号



grep --color -r 'iptables' /etc/* --------------------过滤出/etc/下面的文件含iptables



grep --color -rh 'iptables' /etc/* -------------不显示所在的文件






eg:2

grep -n 'root' /etc/passwd -------


grep --color -n 'root' /etc/passwd ----------------


grep --color '[0-9]' /etc/passwd -------------过滤0-9的数字


grep --color '[a-zA-Z]' /etc/passwd


grep --color 'r.o' 1.txt


grep --color 'r*o' 1.txt ------------查找*号前面的字符


grep -- color 'r.*o' 1.txt ----------------任意一个任意字符,开头是r 结尾是o字符


grep --color 'r\?o' 1.txt----------------匹配o .... o 字符


grep --color -E 'r?o' 1.txt -----------跟脱义用法一E




grep 3:


egrep == grep -E


egrep --color 'r+o' 1.txt ---------匹配一个或多个+号前面的字符


. 任意一个字符

* 星号前面字符零个或多个

.* 任意个任意字符

?0个或1个?前面的字符

+ 1或多个1前面的字符


grep --color 'root|nologin' 1.txt ----------匹配root或者nologin


grep --color 'root' 1.txt |grep --color 'nologin' ---------匹配2次


egrep --color '(rr)+' 1.txt -----------------匹配整体


grep -E --color '(rr) {1,3} ' 1.txt -----匹配最开始的1-3个r字符


grep -E --color '(rr) {5}' 1.txt ------------匹配5对rr


grep -E --color '\(rr\)\{5,6\}' 1.txt

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐