[Chapter 11] 11.6 Variables and Array Assignments
Author: Daniel Gilly & the Staff of O'Reilly & Associates
Date: 1998-08-06T22:00:21Z

#

| Chapter 11 The Awk Scripting Language |

## 11.6 Variables and Array Assignments

Variables can be assigned a value with an = sign. For example:

>     FS = ","

Expressions using the operators +, -, /, and % (modulo) can be assigned to variables.

Arrays can be created with the split function (see below), or they can simply be named in an assignment statement. ++, +=, and -= are used to increment or decrement an array, as in the C language. Array elements can be subscripted with numbers (`array`[1], ..., `array`[`n`]) or with names. For example, to count the number of occurrences of a pattern, you could use the following script:

>     /pattern/ { array["/pattern/"]++ }
>     END { print array["/pattern/"] }

11.5 Operators |  | 11.7 Group Listing of Awk Commands