Go to the first, previous, next, last section, table of contents.


Variables

Variables let you give names to values and refer to them later. You have already seen variables in many of the examples. The name of a variable must be a sequence of letters, digits and underscores, but it may not begin with a digit. Case is significant in variable names; a and A are distinct variables.

A variable name is a valid expression by itself; it represents the variable's current value. Variables are given new values with assignment operators and increment operators. See section Assignment Expressions.

A few variables have special built-in meanings, such as FS, the field separator, and NF, the number of fields in the current input record. See section Built-in Variables, for a list of them. These built-in variables can be used and assigned just like all other variables, but their values are also used or changed automatically by awk. Each built-in variable's name is made entirely of upper case letters.

Variables in awk can be assigned either numeric or string values. By default, variables are initialized to the null string, which is effectively zero if converted to a number. There is no need to "initialize" each variable explicitly in awk, the way you would in C or most other traditional languages.


Go to the first, previous, next, last section, table of contents.