1833875 Members
1877 Online
110063 Solutions
New Discussion

Re: awk command

 
sanjit
Occasional Advisor

awk command

Hello all,

I would like to write a script that would extract the 5th field using the awk command from the lanscan command. Then I would like to take that field and send it to the ifconfig command and send the output to the screen. Can someone show me how its done please. I kinda know you would have to do something like lanscan > awk '/lan/'.... Thank you for all your assistance.
8 REPLIES 8
James R. Ferguson
Acclaimed Contributor

Re: awk command

Hi:

for X in `lanscan|awk 'NR>2 {print $5}'`
do
ifconfig $X
done

...JRF...
boley janowski
Trusted Contributor

Re: awk command

for in `lanscan | awk '{print $5}' | grep -v Net | grep -v Name'
do
ifconfig ${i}
done
Vincenzo Restuccia
Honored Contributor

Re: awk command


for I in `lanscan|grep lan|awk '{ print $5 }'
do
ifconfig $I
done
sanjit
Occasional Advisor

Re: awk command

Hi James, thank you much for your help. One more thing, what does the NR>2 mean?
James R. Ferguson
Acclaimed Contributor

Re: awk command

Hi:

The 'NR' variable is the current record count. 'awk' gives you this implicitly. Thus, I am selecting records from the output of the 'lanscan' where the record number is greater then two (2). As you know, this skips 'lanscan's headings.

Regards!

...JRF...
Vincenzo Restuccia
Honored Contributor

Re: awk command

The ordinal number of the current record from the start of input. Inside a BEGIN action the value is zero. Inside an END action the value is the number of the last record processed.
MANOJ SRIVASTAVA
Honored Contributor

Re: awk command

Hi Sanjit

Try this

lanscan | awk '{print $5}' | grep lan >/tmp/x
for i in 'cat /tmp/x'
do
ifconfig $i
done


Manoj Srivastava
Eric Bramble
New Member

Re: awk command

Here is the same but with only one line

lanscan | awk 'NR>2{system("ifconfig "$5)}'