AWK built-in functions
AWK has the mathematical functions like exp
, log
, sqrt
, sin
, cos
, atan2
, etc. built-in, other built-in functions are:
length
the length of its argument taken as a string, or of$0
if no argument.rand
random number between0
and1
srand
sets seed for rand and returns the previous seed.int
truncates to an integer valuesubstr(s, m, n)
then
-character substring ofs
that begins at positionm
counted from1
.index(s, t)
the position ins
where the stringt
occurs, or0
if it does not.match(s, r)
the position ins
where the regular expressionr
occurs, or0
if it does not. The variablesRSTART
andRLENGTH
are set to the position and length of the matched string.split(s, a, fs)
splits the strings
into array elementsa[1], a[2], ..., a[n]
, and returnsn
. The separation is done with the regular expressionfs
or with the field separatorFS
iffs
is not given. An empty string as field separator splits the string into one array element per character.sub(r, t, s)
substitutest
for the first occurrence of the regular expressionr
in the strings
. Ifs
is not given,$0
is used.gsub
same as sub except that all occurrences of the regular expression are replaced; sub and gsub return the number of replacements.sprintf(fmt, expr, ... )
the string resulting from formattingexpr ...
according to theprintf
formatfmt
.system(cmd)
executes cmd and returns its exit status.tolower(str)
returns a copy of str with all upper-case characters translated to their corresponding lower-case equivalents.toupper(str)
returns a copy of str with all lower-case characters translated to their corresponding upper-case equivalents.
Get hands-on with 1400+ tech skills courses.