Linux 中 grep -P 选项 perl正则 限制两侧进行匹配

 

001、

[root@PC1 test3]# echo "Hello, my name is aming."|grep -P '(?<=Hello, ).*(?= aming.)'
Hello, my name is aming.

 

002、

[root@PC1 test3]# ifconfig | grep -P '(?<=inet).*(?=netmask)'
        inet 192.168.184.128  netmask 255.255.255.0  broadcast 192.168.184.255
        inet 127.0.0.1  netmask 255.0.0.0
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255

。 

 

ref:

01:https://blog.51cto.com/u_15127506/4147133 

 

posted @ 2024-06-23 14:53  小鲨鱼2018  阅读(5)  评论(0编辑  收藏  举报