LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   How to extract the interface number from ifconfig -a (http://www.linuxquestions.org/questions/linux-networking-3/how-to-extract-the-interface-number-from-ifconfig-a-659673/)

pooppp 08-01-2008 03:16 AM

How to extract the interface number from ifconfig -a
 
1.Ifconfig -a will display all interfaces like eth2,eth3 etc., right..
I need to extract 2,3 like tht only if the interface HW address starts with 00:0C

2.& I got script for extracting HWaddr starts with 00:0C as below
ifconfig -a | awk '/HWaddr 00:0C/{print $1}'
How to store the interface outputed above in a variable?

Pearlseattle 08-01-2008 03:23 AM

Quote:

How to store the interface outputed above in a variable?
You mean something like

MYVAR=$(ifconfig -a | awk '/HWaddr 00:0C/{print $1}')

echo $MYVAR

?

pooppp 08-01-2008 04:53 AM

u r correct
 
i tried with wht u gave..but not working

jomen 08-01-2008 05:22 AM

This was only an example - try to understand what it does.
Quote:

You mean something like
Take a look at the output of ifconfig -a first.

For me it outputs the string "Hardware Adresse"
so for me - this example works:

MYVAR=$(ifconfig -a | awk '/Hardware/{print $1}')
echo $MYVAR

only an example too;)

pooppp 08-04-2008 05:54 AM

Thank u..Working


All times are GMT -5. The time now is 11:52 AM.