Chapter 9. Functions
This chapter describes
built-in functions, which fall into three categories: numeric, string, and
gawk provides additional groups of
functions to work with values that represent time, do bit manipulation, sort
arrays, provide type information, and internationalize and localize
Besides the built-in functions,
has provisions for writing new functions that the rest of a program can use.
The second part of this chapter describes these
user-defined functions. Finally, we explore
indirect function calls, a
gawk-specific extension that
lets you determine at runtime what function is to be called.
Built-in functions are always available for
awk program to call. This section defines all the built-in functions in
awk; some of these are mentioned in other
sections but are summarized here for your convenience.
Calling Built-in Functions
To call one of
functions, write the name of the function followed by arguments in
parentheses. For example, ‘
atan2(y + z,
1)’ is a call to the function
atan2() and has two arguments.
Whitespace is ignored between the built-in function name and the opening parenthesis, but nonetheless it is good practice to avoid using whitespace there. User-defined functions do not permit whitespace in this way, and it is easier to avoid mistakes by following a simple convention that always works—no whitespace after a function name.
Each built-in function accepts a certain number of arguments. In some ...