您的位置:首页 > 博客中心 > 网络系统 >

linux正则表达式之取ip

时间:2022-04-03 13:12

使用ifconfig取出网卡eth0的ip地址

方法1:sed

[root@ZHOUQIZHONG ~]# ifconfig eth0 |sed -nr‘2s#.*dr:|Bca.*##gp‘

10.0.0.200 

[root@ZHOUQIZHONG ~]#

方法2:sed

[root@ZHOUQIZHONG ~]# ifconfig eth0 |sed -nr‘2s#.*dr:(.*)Bca.*#\1#gp‘

10.0.0.200 

[root@ZHOUQIZHONG ~]#

方法3:sed+cut

[root@ZHOUQIZHONG ~]# ifconfig eth0 |sed -n‘2p‘|cut -d ‘:‘ -f2 |cut -d ‘ ‘ -f1

10.0.0.200

[root@ZHOUQIZHONG ~]#

方法4:awk

[root@ZHOUQIZHONG ~]# ifconfig eth0 |awk -F ‘[: ]+‘‘NR==2{print $4}‘

10.0.0.200

[root@ZHOUQIZHONG ~]#

方法5:awk

[root@ZHOUQIZHONG ~]# ifconfig eth0 |awk -F‘addr:|Bcast:‘ ‘NR==2{print $2}‘

10.0.0.200 

[root@ZHOUQIZHONG ~]#

......

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<一天变一个样

本文出自 “” 博客,请务必保留此出处

本类排行

今日推荐

热门手游