Linux 中 grep -P 選項 perl正則 限制兩側進行匹配

小鲨鱼2018發表於2024-06-23

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

相關文章