天天看點

取出IP位址的指令

<a href="http://xuchengji.blog.51cto.com/attachment/201004/21/160472_12718570134Ghg.png"></a>

#ifconfig eth0 |grep inet |sed ‘2d’ |cut –c 16- |cut –d ‘ ‘ –f 1 |cut –d ‘ ‘ –f 2 |cut –c 6-

# ifconfig eth0 |sed -n '2p' |sed  's/^.*addr: //g'|cut -d ' ' -f 1

也可以實作

#ifconfig eth0 | sed -n '2p'| |sed 's/^.addr : //g' |sed  's/Bcast.*//g'

#ifconfig eth0 | awk '{FS=":"} {print $2}' |sed -n '2p' |cut -d ' ' -f 1

#ifconfig eht0 |awk '{FS=":"} {print $2}' |sed -n '2p'|sed 's/Bcast//g'

#ifconfig eht0 |awk '/inet/ {split ($2,x,":") ;print x[2]}'

通過這幾個指令,我感覺到了grep,sed,cut,awk等正規表達式相關指令及工具的強大。這個實驗在REDHAT ENTERPRISE LINUX 5.0上實作的。

本文轉自xcjgutong 51CTO部落格,原文連結:http://blog.51cto.com/xuchengji/302520

繼續閱讀