Linux 之 正则实践

正则实践

1.通过awk获取IP地址
[root@localhost ~]# ifconfig eth2 | grep inet
                    inet addr:10.3.151.25  Bcast:10.3.151.255  Mask:255.255.255.0
                    inet6 addr: fe80::250:56ff:fe80:6e7e/64 Scope:Link
[root@localhost ~]# ifconfig eth2 | grep "\binet\b"
                    inet addr:10.3.151.25  Bcast:10.3.151.255  Mask:255.255.255.0
[root@localhost ~]# ifconfig eth2 | grep "\binet\b" | awk '{print $0}'
                    inet addr:10.3.151.25  Bcast:10.3.151.255  Mask:255.255.255.0
[root@localhost ~]# ifconfig eth2 | grep "\binet\b" | awk '{print $2}'
addr:10.3.151.25
[root@localhost ~]# ifconfig eth2 | grep "\binet\b" | awk '{print $2}'| awk -F ':' '{print $2}'
10.3.151.25

猜你喜欢

转载自blog.51cto.com/12965094/2115003