返回顶部

文本三剑客之sed,提取IP地址

Sed网卡取IP

 

[root@centos8 ~]#ifconfig ens160|sed  -n '2p'|sed 's/^.*inet //'|sed 's/ .*//'  

 

[root@centos8 ~]#ifconfig ens160|sed  -rn '2s/^([^0-9]+)([0-9.]+)( .*)$/\2/p'      

 

[root@centos8 ~]#ifconfig ens160|sed  -rn '2s/^[^0-9]+([0-9.]+) .*$/\1/p'  

 

=ifconfig |sed  -rn "2s/[^0-9]+([0-9.]+) .*$/\1/p"  

 

#ifconfig |sed -n '2s/^.*inet //;s/netmask.*//p'

 

#ifconfig |sed -n '2s/^.*inet //p' |sed -n 's/netmask.*//p'

 

#ifconfig |sed -En '2s/^[^0-9]+([0-9.]+).*$/\1/p'

 

#ifconfig |sed -nr '2s/^[^0-9]+([0-9.]{7,15}).*/\1/p'

 

#ifconfig |sed -nE '2s/[^0-9]+([0-9.]+).*/\1/p'

 

#ifconfig |sed -nr '2s/[^0-9]+([0-9.]+).*/\1/p'

 

#ifconfig eth0 |sed -nr '2s/(.*inet) ([0-9].*) (netmask.*)/\2/p'

 

posted @ 2020-08-11 20:43  九尾cat  阅读(1265)  评论(0编辑  收藏  举报