1. ifconfig eth0 |grep "inet addr"|awk '{print $2}'|cut -f2 -d ':' 
  2.  
  3. 分析
  4. [root@regstd linux]# ifconfig eth0 |grep "inet addr"  //匹配"inet addr"行
  5.           inet addr:10.158.120.81  Bcast:10.158.120.255  Mask:255.255.255.0 
  6.  
  7. [root@regstd linux]# ifconfig eth0 |grep "inet addr"|awk '{print $2}'
    //截取第2列
  8. addr:10.158.120.81 
  9.  
  10. [root@regstd linux]# ifconfig eth0 |grep "inet addr"|awk '{print $2}'|cut -f1 -d ':' 
  11. addr 
  12. [root@regstd linux]# ifconfig eth0 |grep "inet addr"|awk '{print $2}'|cut -f2 -d ':' 
  13. 10.158.120.81 

//以:为分隔符,截取第2列