For Programmers: Free Programming Magazines  


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









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 newbie question:extract last argument in a line when number of arguments is unknown
yaniv

2004-03-19, 8:23 pm

Hi,

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

Is there a way for doing it in a single awk command?
How can it be done generally? (without the one command limitation)

Any help would be appreciated,

thanks,
yaniv
Patrick TJ McPhee

2004-03-19, 8:23 pm

In article <d742ebad.0402240203.46836e43@posting.google.com>,
yaniv <valiky@hotmail.com> wrote:

% I need to extract the last argument of a given line, when number of
% arguments in line is unkown.

You might want to give an example of what you hope to achieve. Given
this:

awk -f somefile.awk here are some arguments

there's a variable called ARGC which will be set to 5 and an array
called ARGV. ARGV[1] will be set to "here", ..., ARGV[4] will be
set to "arguments". ARGV[4] is the same as ARGV[ARGC-1].

On some systems, this will not work. The reason is that awk on those systems
s the original, pre-1987 awk, while the language discussed in this group
is invoked using the name nawk. The only widely used system with this
characteristic is Solaris, and you can fix it by setting the path
appropriately (to start with /usr/xpg4/bin).

--

Patrick TJ McPhee
East York Canada
ptjm@interlog.com
Sponsored Links







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

Copyright 2008 codecomments.com