grep 命令使用指南

                                      grep 命令                                           

grep参数:

-E:等同于egrep

-o:只匹配你想要的内容,下面是示例:

[root@localhost ~]# cat /data/game/config/server_config.txt | grep mysql_port | egrep -o "[0-9]+"
3306
[root@localhost ~]# cat /data/game/config/server_config.txt | grep mysql_port | egrep "[0-9]+"
{mysql_port, 3306}.

使用grep命令进行多个条件查询:
[root@TX-2 tmp]# cat a.txt error error error error error ERROR ERROR ERROR ERROR ERROR ERROR ERROR [root@TX-2 tmp]# cat a.txt | grep -E "error|ERROR" error error error error error ERROR ERROR ERROR ERROR ERROR ERROR ERROR [root@TX-2 tmp]#
使用grep匹配ip地址:
[root@localhost ~]# egrep "[0-9]+.[0-9]+.[0-9]+.[0-9]+." a 123.123.123.123 123.123.123 [root@localhost ~]# egrep "[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}." a 123.123.123.123 123.123.123
原文地址:https://www.cnblogs.com/tangshengwei/p/5026403.html