Example1、显示/etc/passwd文件中不以/bin/bash结尾的行;
~]#grep-v"/bin/bash$"/etc/passwd ~]#grep-v"/bin/bash\>"/etc/passwd
Example2、找出/etc/passwd文件中的两位数或三位数;
[root@CentOS7-171~]#grep"[0-9]\{2,3\}"/etc/passwd mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTPUser:/var/ftp:/sbin/nologin ...以下省略...
Example3、找出/etc/grub2.cfg文件中,以至少一个空白字符开头,且后面非空白字符的行;
[root@CentOS7-171~]#grep"^[[:space:]]\+[^[:space:]]"/etc/grub2.cfg load_env setdefault="${next_entry}" setnext_entry=
Example4、找出"netstat -tan"命令的结果中以'LISTEN'后跟0、1或多个空白字符结尾的行;
[root@CentOS7-171~]#netstat-tan|grep"LISTEN[[:space:]]*$" tcp00192.168.122.1:530.0.0.0:*LISTEN tcp000.0.0.0:220.0.0.0:*LISTEN tcp00127.0.0.1:6310.0.0.0:*LISTEN tcp00127.0.0.1:250.0.0.0:*LISTEN tcp600:::8009:::*LISTEN原文链接:https://www.f2er.com/regex/358504.html