Link to home
Start Free TrialLog in
Avatar of ashsysad
ashsysadFlag for United States of America

asked on

Awk syntax needed

I have a command output like this:

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
10.20.66.0      0.0.0.0         255.255.255.0   U         0 0          0 eth0
169.254.95.0    0.0.0.0         255.255.255.0   U         0 0          0 usb0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 usb0
0.0.0.0         10.20.66.1      0.0.0.0         UG        0 0          0 eth0


I need an awk statement that will output the 3rd line of the output and assigns to a varaible.
10.20.66.0      0.0.0.0         255.255.255.0   U         0 0          0 eth0

In addition, I want to assign "eth0" (last item) to another variable.  Please assist.

Thanks !
Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

NR==3{linethree=$0;linethreelast=$NF}
Avatar of ashsysad

ASKER

I'm getting syntax error:

# netstat -rn | awk {NR==3'{linethree=$0;linethreelast=$NF}'}
awk: {NR==3{linethree=$0;linethreelast=$NF}}
awk:       ^ syntax error


I'm not that comfortable with AWK. Please give me the full syntax.

ASKER CERTIFIED SOLUTION
Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thankyou !