AwkOnWindowsHowto
rough cut - needs edit
3) awk command line switches/usage
from a win32 cmd.exe prompt: D:\!\utl > awk95.exe
usage: awk95.exe [-F fs] [-v var=value] [-f progfile | 'prog'] [file ...]
-version or --version; print version and exit; (was -V;
prints: awk version 20070501 But is actually 20071023 version)
- stdin
-- explicit end of args
-safe see above
-f progfile next argument is program filename
-f - read the program from stdin
-F fs set field separator FS to value of fs
(nojoy -F "" to set FS to null; use -v FS="")
-v var=value -v a=1 to be done NOW. one -v for each variable
(\a \v \xhh Not interpreted in value; use octal \nnn instead)
-d[n] undocumented -d does debug dump
examples:
awk95 "BEGIN {print \"Hello, World!\"}"
|- Hello, World! #: |- indicates output of above
awk95 -v s="Hello, World!" BEGIN{print(s)}
|- Hello, World! #: pgm needs no " since no spaces
awk95 -v s=Hello,\040World! BEGIN{print(s)}
|- Hello, World! #: \040 is octal for space
echo BEGIN {print "Hello, World!"} | awk95 -f -
|- Hello, World! #: read the program from stdin
cmd.exe special: & " ^ % < > | =
5) miscellaneous
valid filenames: /dev/stdin /dev/stdout /dev/stderr
array SYMTAB holds values of variables
for(varname in SYMTAB) \
if ((varname != "ENVIRON") && (varname != "ARGV") \
&& (varname != "SYMTAB") && (varname != "array")) \
printf("SYMTAB[%s]=%s\n", varname, SYMTAB[varname])
The `**' and `**=' operators are valid instead of ^
#: system() returns errorcode/256
eg system("%awk% BEGIN{exit(256)})
#: s|getline; n = close(s); is ok Except when n=-1 then message
#: regular expression metacharacters: \ . ^ $ [ ] | + * ? ( )
#: filenames may Not contain: \ / : * ? " < > |
#: cmd.exe special: & " ^ % < > | =
#: start ["title"] [/min|/max] [/low|/high] [/wait] [/b]
#: ENVIRON[] -- remember indices are case sensitive
assoc .awk=awkfile
ftype awkfile=D:\!\utl\awk95.exe -f "%1" %*
5) timings
timethis "echo.BEGIN{n=0+n;while(n--);} | %awk% -f - -v n=2e6"
timethis %awk% -v n=2e6 BEGIN{n=0+n;while(n--);}
-v n=2e6 -v s=The\040current\040time\040is:\04012:30:49.80 -v x=xx
for 2e6 ops; MOPS - the ; time subtracted from next
awk95 nawk gawk mawk
; 0.73 1.00 1.37 1.20
i++; 1.69 1.54 2.32 5.56
i = k; 0.76 0.46 2.77 3.03
i = A[k]; 0.37 0.18 0.63 1.80
i = rand(); 0.36 0.18 1.82 1.96
i = rand(1); 1.07 0.59 nojoy nojoy
i = srand(1); 0.89 0.56 0.037 0.96
A[n] = n; 0.037 0.029 0.00091 0.20
i = index(s,x); 0.60 0.57 0.71 1.01
i = substr(s,32); 0.35 0.22 0.23 0.90
i = tolower(s); 0.15 0.079 0.088 0.88
i = split(s,A); 0.026 0.019 0.011 0.31