方法1:sed命令
1
2
|
[root@oldboyedu ~]
# ifconfig eth0 |sed -n '2p' |sed's#^.*addr:##g'|sed 's# B.*$##g'
10.0.0.50
|
方法2:cut
1
2
|
[root@oldboyedu ~]
# ifconfig eth0|grep 'inetaddr'|cut -d ":" -f2|cut -d " " -f1
10.0.0.50
|
方法3:普通awk 使用2遍
1
2
|
[root@oldboyedu ~]
# ifconfig eth0|grep 'inet addr'|awk -F ":" '{print $2}'|awk '{print $1}'
10.0.0.50
|
方法4:awk同时多分隔符法
1
2
|
[root@oldboyedu ~]
# ifconfig eth0|grep 'inetaddr'|awk -F '[ :]' '{print $13}'
10.0.0.50
|
方法5:awk同时多分隔符法
1
2
3
4
|
[root@oldboyedu ~]
# ifconfig eth0|sed -n '2p'|awk-F '[ :]+' '{print $4}'
10.0.0.50
[root@oldboyedu ~]
# ifconfig eth0 |awk -F'[ :]+' 'NR==2 {print $4}'
10.0.0.50
|
方法6:sed(正则)
1
2
|
[root@oldboyedu ~]
# ifconfig eth0 |sed -nr '2s#^.*dr:(.*) B.*$#\1#gp'
10.0.0.50
|
方法7:grep-perl正则方法
1
2
|
[root@show ~]
# ifconfig eth0|grep -Po '(?<=dr:)[0-9.]+'
10.0.0.50
|
转载于:https://blog.51cto.com/2690403167/1966440