Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageIn 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
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.