User-defined Functions Complicated awk programs can often be simplified by defining your own functions. Syntax of Function Definitions Definitions of functions can appear anywhere between the rules of the awk program. Thus, the general form of an awk program is extended to include sequences of rules and user-defined function definitions.
Functions share the same pool of names as variables and arrays.
When the function is called, the argument names are used to hold the argument values given in the call. The local variables are initialized to the null string. It is the most important part of the definition, because it says what the function should actually do . Thus, if three argument values are given, the first three names in parameter-list are arguments, and the rest are local variables. It follows that if the number of arguments is not the same in all calls to the function, some of the names in parameter-list may be arguments on some occasions and local variables on others.