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