passing arguments to awk scripts
Guenter Steinbach
steinbac at hpl-opus.hpl.hp.com
Tue Mar 12 15:41:43 AEST 1991
In nawk you can access ARGV and ARGC similar to C.
Get the book "The AWK programming language" by Aho, Kernighan (sp?) and
Weinberger themselves. Here is a piece of a script that I lifted
from the book, it should give you an idea of how this works:
nawk 'BEGIN { # deal with args
for(i=1;ARGV[i] ~ /^[0-9]+$/;i++) { # collect numbers
fld[++nf] = ARGV[i] # into array fld
ARGV[i] = "" # remove from ARGV
}
if(i >= ARGC) ARGV[ARGC++] = "-" # no file name: stdin
} # end of BEGIN
at this point, only file names or "-" are left in ARGV, and
any integer number arguments are collected in fld.
Good luck.
Guenter Steinbach gunter_steinbach at hplabs.hp.com
More information about the Comp.unix.misc
mailing list