An Awk Primer/User-defined Functions

Awk supports user-defined functions.

A function definition is specified outside of patterns and actions and looks like For example, the following program, for each record, prints sum of squares of its first two fields:

A function call should not contain any intervening whitespaces between the function name and the left parenthesis. This applies only to user-defined functions, and the goal is to avoid confusion with the concatenation operator:

In order to return a value, use the  statement:

In order to use local variables, they should be specified at the end of the parameter list, but not in the function call: By convention, local variables are separated from parameters by extra spaces.

As a GAWK extension, there is an indirect function call. It looks like this: @(comma-separated list of parameters>) Example: