方法1:sed查询打印
[root@Linux9 ~]# ifconfig eth0 |grep "inet addr:" |sed 's/Bcast.*$//'g |sed 's/.*://g' 192.168.25.57
方法2:awk查询打印
[root@Linux9 ~]# ifconfig eth0 |grep "inet addr:" |sed 's/Bcast.*$//'g |awk -F ":" {'print $2'} 192.168.25.57
方法3:cut分段打印
[root@Linux9 ~]# ifconfig eth0 |grep 'Bcast' |cut -d ':' -f3|cut -d " " -f1 192.168.31.255
方法4:awk查询打印子网掩码
[root@Linux9 ~]# ifconfig eth0 |grep 'Mask' |awk -F: '{print $4}' 255.255.240.0
转载于:https://blog.51cto.com/461205160/1742614