gawk

Implementation of programming language AWK

gawk is GNU AWK implementation, written in C and distributed under GNU GPL license.

Examples:

Hello, World!:

Example for versions gawk 3.1.6, mawk 1.3.3

The printing is done with BEGIN pattern, i.e., before processing the input.

BEGIN { print "Hello, World!" }

Factorial:

Example for versions gawk 3.1.6, mawk 1.3.3

This example uses iterative factorial definition. Individual statements within code block can be separated with semicolons (;) or new lines.

BEGIN {
    f = 1
    print "0! = " f
    for (i=1; i<17; i++) {
        f *= i
        print i "! = " f
    }
}

Fibonacci numbers:

Example for versions gawk 3.1.6, mawk 1.3.3

This example uses iterative definition of Fibonacci numbers. fib is an associative array, and pr is a string.

BEGIN {
    fib[1] = 1
    fib[2] = 1
    for (i=3; i<17; i++)
        fib[i] = fib[i-1]+fib[i-2]
    pr = ""
    for (i=1; i<17; i++)
        pr = pr fib[i] ", "
    print pr "..." 
}