O'Reilly logo

Learning AWK Programming by Shiwang Kalkhanda

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 }
  • function_name: This is the name of the function to be defined. A valid function name could consist of letters, digits, and underscores, but doesn't start with a digit and could be 52 letters in length. In a single AWK program, a variable name, array, or function should be unique. AWK keywords cannot be used as function names.
  • argument ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required