-
Book Overview & Buying
-
Table Of Contents
Linux Command Line and Shell Scripting Bible - Third Edition
By :
You're not limited to just using the built-in functions available in gawk. You can create your own functions for use in gawk programs. This section shows you how to define and use your own functions in gawk programs.
To define you own function, you must use the function keyword:
function name([variables])
{
statements
}
The function name must uniquely identify your function. You can pass one or more variables into the function from the calling gawk program:
function printthird()
{
print $3
}
This function prints the third data field in the record.
The function can also return a value using the return statement:
return value
The value can be a variable, or an equation that evaluates to a value:
function myrand(limit)
{
return int(limit * rand())
}
You can assign the value returned from the function to a variable in the gawk program:
x = myrand(100)
The variable contains the value returned from the function.
Change the font size
Change margin width
Change background colour