linux下取IP(正则)

linux下取IP(正则)

常见方法:

 ifconfig eth0|grep "inet addr"|awk -F ":" '{print $2}'|awk '{print $1}'

ifconfig eth0|sed -n '2p'|awk -F ":" '{print $2}'|awk '{print $1}'

ifconfig eth0|egrep -o '19.*117'

 高级方法:

ifconfig eth0|sed -nr '2s#^.*dr:(.*) Bc.*$#\1#gp'

ifconfig eth0|awk -F '[: ]+' 'NR==2 {print $4}'

直接过滤ip配置文件方法: 自动获取不行。

grep IPADD /etc/sysconfig/network-scripts/ifcfg-eth0|cut -d= -f2

猜你喜欢

转载自www.cnblogs.com/su-root/p/9972051.html
今日推荐