AWK reference
String functions
asort(source [, dest [, how ] ]) # Sort values and replace indices
gensub(regexp, replacement, how [, target]) # gsub with multiple matches in the replacement
gsub(regexp, replacement [, target])
index(in, find)
length([string])
match(string, regexp [, array]) # Returns index of the match, or zero if not found
patsplit(string, array [, fieldpat [, seps ] ]) # Split by content like FPAT
split(string, array [, fieldsep [, seps ] ])
sprintf(format, expression1, ...)
strtonum(str)
sub(regexp, replacement [, target])
substr(string, start [, length ])
tolower(string)
toupper(string)
asort, gensub, patsplit and strtonum are not on POSIX, but busybox awk supports gensub.
Regular Expressions
Bracket Expressions:
[:alnum:] # Alphanumeric characters
[:alpha:] # Alphabetic characters
[:blank:] # Space and TAB characters
[:cntrl:] # Control characters
[:digit:] # Numeric characters
[:graph:] # Characters that are both printable and visible
[:lower:] # Lowercase alphabetic characters
[:print:] # Printable characters
[:punct:] # Punctuation characters
[:space:] # Space characters (such as space, TAB, and formfeed, to name a few)
[:upper:] # Uppercase alphabetic characters
[:xdigit:] # Characters that are hexadecimal digits
Time functions
mktime(datespec) # Turn datespec into a timestamp
strftime(format, timestamp) # Format the timestamp based on the format string
systime() # Return the Unix time
Not on POSIX but both mawk and busybox support this functions.
Controlling Array Traversal
Sort by index/value string/numeric ascending/descending:
PROCINFO["sorted_in"] = "@ind_str_asc" # @ind_num_asc val_str_asc @val_num_asc @ind_str_desc
for (i in array)
...
Custom function:
comp_func(i1, v1, i2, v2) {
return v1 - v2 # Sort by value
return i1 - i2 # Sort by index
}
PROCINFO["sorted_in"] = "comp_func"
for (i in array)
...