#! /usr/bin/awk -f # awk -- template for an awk script, with option processing # $Id$ # Carlos Duarte , 990302/990402 function usage() { printf "Usage: awk -f script.awk -- \ [-f arg] [-n] [files...]\n" exit(2); } BEGIN { ## scan for options i=0 while (++i< ARGC) { s = ARGV[i] if (s !~ /^-/) break if (s == "--") { ++i break } if (s == "-n") { # flag option n_flag++; continue } if (s == "-f") { # one arg option if ((f_arg = ARGV[++i]) == "") usage(); continue } printf "%s -- unrecognized option\n", substr(s, 2); usage(); exit; } ## remap ARGC/ARGV without seen options j=0; while (i