awk -v k1=v1... -f src1.awk --source 'CODE' -f src2.awk... # I.e. if no -f given then default --source is inferred awk -v k1=v1... src2.awk... BEWARE \s does not work! Character support. Can specify character sequences like \n or \t or \u000a or \0a? AIX and Solaris (even nawk) awk doesn't understand regexp matcher \w SOLARIS awk is crippled. -v doesn't work. DOES WORK WITH nawk and xpg4. Something else doesn't work, I don't remember what. Maybe switch for setting ORS? Maybe some regular expression character classes don't work, I think the [[:space:]] and similar char classes don't work. Solaris nawk === regular legacy awk. /usr/xpg4/bin/awk === regular legacy awk. IIRC switches to specify inline code and code files differ. But data input with no input switches works the same for all variants. stdin | awk '...' awk '...' file.path Can freely intermix multiple inline code blocks and source files by using multiple -f and --source switches in any position. I believe that these two are always equal (exc. for Solaris awk!): awk -v name=val... in AWK code: BEGIN { name = val ...} So generally, do use -v and don't use var-specific switches like -F and don't initialize built-in variables in the BEGIN block. CODE: x; # comment to EOL /egrep_regexp/|relational_expr|BEGIN|END { action statements} [defaults-to-all] [defaults to: { print }] Other variants of matcher: &&, ||, ?, (, !, "start_regexp,stop_regexp" function name(params) { statements } Must explicitly return if you want a return value (i.e. last expression value will not be returned). Can only return a scalar, not an assoc. array. Parameters by value except that assoc. arrays passed by ref. Local variables: just define extra params and they will behave as locals. Data Types No reference variables. null is just "". (null == "") is true, so you gain nothing by using 'null' and it's misleading. Just use "". string Double-quoted with \-escapes. Does not do $variable interpolation. floating-point number 1-dimensional expression-indexed assoc. arrays, aka hashes THERE ARE NO LISTS/ARRAYS! (x in array) boolean delete array delete array[key] By just evaluating a reference like this, an element is instantiated: if (x[nosuch] == 7)... ==> x[nosuch} == "" Though the indexes are internally strings, and documented as that, if you use integral index strings then they are sorted (at least for 'for x in a' loop) as if native integers. Integer index values apparently With integer keys, Gnu awk always iterates in key order. Iteration order is entirely unpredictable with nsh awk. get implicitly converted to strings correctly, because this works too! Like Perl, type is determined by evaluation context. CONVERSIONS To number: 0 + x To string: "" + x (internally uses CONVFMT and sprintf except integers as integers) There is some special magic for "numeric strings". ONLY user-input strings of numbers. Default values: 0, "" += and similar operators do not work with strings. Must do 'x = x addition'. Does have ++, etc. operators Special variables ARGC ARGIND ARGV RS INPUT record separator. Single char or regexp. Default null means blank lines + it adds \n to FS. RT defaults to what RS matched, Record Terminator FS obviously, can be set by -F switch also. Single char or regexp. Default splits into character fields. ' ' is magic value meaning \s+. FIELDWIDTHS breaks into fields by offsets $0 input record $1, $2... input fields NF number of input fields Modifying the input vars causes $0 and deriveds to be regenerated. CONVFMT (sprintf formatter for numbers) OFMT same for output unless integer. Defaults to %.6g. OFS defaults to a space ORS [n.b. Output RS === ORS, but Input RS === RS] ENVIRON array FILENAME NR Recnum (absolute) FNR Input recnum within FILENAME IGNORECASE Controls all regexp and string ops PROCINFO array RSTART, RLENGTH Action Operators (besides the usuals) space string concat GOTCHA!!! NOT: ... "str1" + "str2" or strV1 + strV2, because concat is: "str1" "str2" or strV1 strV2 expr ~ /re/, expr !~ /re/ (implies no ^ or $) next (like Perl) nextfile print [>[>]] appends ORS. By default prints $0 and ORS. printf fmt, expr-list [>[>]] file] retval = system(cmd-line) Also has | pipe writing Magic file names Pseudo /dev/x and network destinations Reading them gives specialized info. Slurp entire files (or stdin) into $0: -v RS='\x04' or BEGIN{RS="\x04"} Similar to: perl -pi -we 's/x/y/' awk -v RS='\x04' '{ print gensub("x", "y", "g") }' ??? Even \s doesn't work with gawk. Forget \S! For example: awk -v RS='\x04' '{ print gensub(/^\S+\s+/, "", "g") }' if gensub not available, then similarly: awk -v RS='\x04' '{ gsub("x", "y"); print; }' ??? Even \s doesn't work with gawk. Forget \S! For example: awk -v RS='\x04' '{ gsub("/\S+\s+/, ""); print; }' General substitution in a string like perl -we '$x =~ s/x/y/;' gsub(/x/, y, x); Win->Unix line delims with gsub: awk -v RS='\x04' '{ gsub(/\r/, ""); print; }' in > out sub-string indexing (like for 'substr' and 'index' functions) is 1-based, not 0-based! Regexp doesn't understand \d. Regexp imply no ^ or $, at least for top-level patterns, match functions, ~. Generally has no switch statement, but gawk can be compiled with it. Print without trailing newline, like echo -n / echo '\c': BEGIN { ORS = "" }