How to cut ifconfig to get eth* details alone?

谁都会走 提交于 2020-01-06 20:00:00

问题


I'm writing a script to print ethtool details of ifconfig.

Sample output should be from ifconfig is like,

eth0
eth1
eth2

I have tried using below command,

root@bt# ifconfig | cut -d ":" -f 1 

But could not able to achieve the same.

Actually, i need to get these eth* and pass in

root@bt# ethtool <arg1> where arg1=eth*

to get results :-) can you please help me to get crop from ifconfig. ?


回答1:


With grep & ifconfig :

ifconfig | grep -o '^eth[0-9]\+'

Or with only grep :

grep -oP '^ *\Keth[0-9]+' /proc/net/dev



回答2:


No.

$ awk -F: '$1 ~ "eth" { print $1 }' /proc/net/dev
  eth0


来源:https://stackoverflow.com/questions/12664473/how-to-cut-ifconfig-to-get-eth-details-alone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!