问题
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