For Programmers: Free Programming Magazines  


Home > Archive > AWK > March 2004 > Re: newbie question:extract last argument in a line when number of









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: newbie question:extract last argument in a line when number of
Stefan Lagotzki

2004-03-19, 8:23 pm

yaniv asked:
> I need to extract the last argument of a given line, when number of
> arguments in line is unkown.


The number of fields is not unknown, you may search the awk-manual for
"Built-in Variables" --> NF.

stefan2@platon:~/test> awk '{print $NF}' << EOF
> 1 2 3 4
> 1 2 3
> 1 2
> 1
> EOF

4
3
2
1

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com