AWK allows us to define user-defined functions. A large complex can be divided into functions where each function performs a specific task. These functions can be written and tested independently. This functionality means that we can reuse code.
User-defined functions
Function definition and syntax
The definition of functions can be given anywhere between the rules of an AWK program. It is not mandatory in AWK to define a function before calling it because AWK first reads the entire program before it starts to execute it. The general syntax for defining a user-defined function is as follows:
function function_name(argument1, argument2, …local variable.) {
body-of-function
...