Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

displaying next to last field in file

Status
Not open for further replies.

noiz

IS-IT--Management
Apr 19, 2001
17
US
First i want to thank every one who took time to help me last time. I have a file where i want to print the second to last field of each line but the lines aren't all the same length. Is their a variable in awk i can use that will specify the second to last field?

Example

a b c d
a b c d e f
a b c d e f g
a b c d e f g h

output: c e f g

Thank you

zion
<><
=-)
 
Hi noiz-

Sure it's done like this:

awk '{print $(NF-1)}' infile

NF is a built in variable for the number of fields in
each line, so this means print what is held in the
last field (minus 1).

HTH



flogrr
flogr@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top