Awk syntax needed

I have a command output like this:

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface   U         0 0          0 eth0   U         0 0          0 usb0     U         0 0          0 usb0         UG        0 0          0 eth0

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

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

Thanks !
Who is Participating?
simon3270Connect With a Mentor Commented:
Too many brackets!  The "NR==3" part is the bit which determines whether the command is run, and the command to run is in the brackets.

    netstat -rn | awk 'NR==3{linethree=$0;linethreelast=$NF}'

But you do then have to do something with the data.  For example:

    netstat -rn | awk 'NR==3{linethree=$0;linethreelast=$NF}
    END{printf "Device was %s, and last line was <%s>\n",linethreelast,linethree}'
ashsysadAuthor Commented:
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.

ashsysadAuthor Commented:
Thankyou !
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.