gawk: Using Variables

1 
1 6.1.3.1 Using Variables in a Program
1 ....................................
1 
1 Variables let you give names to values and refer to them later.
1 Variables have already been used in many of the examples.  The name of a
1 variable must be a sequence of letters, digits, or underscores, and it
1 may not begin with a digit.  Here, a "letter" is any one of the 52
1 upper- and lowercase English letters.  Other characters that may be
1 defined as letters in non-English locales are not valid in variable
1 names.  Case is significant in variable names; 'a' and 'A' are distinct
1 variables.
1 
1    A variable name is a valid expression by itself; it represents the
1 variable's current value.  Variables are given new values with
1 "assignment operators", "increment operators", and "decrement operators"
1 (⇒Assignment Ops).  In addition, the 'sub()' and 'gsub()'
1 functions can change a variable's value, and the 'match()', 'split()',
1 and 'patsplit()' functions can change the contents of their array
1 parameters (⇒String Functions).
1 
1    A few variables have special built-in meanings, such as 'FS' (the
1 field separator) and 'NF' (the number of fields in the current input
1 record).  ⇒Built-in Variables for a list of the predefined
1 variables.  These predefined variables can be used and assigned just
1 like all other variables, but their values are also used or changed
1 automatically by 'awk'.  All predefined variables' names are entirely
1 uppercase.
1 
1    Variables in 'awk' can be assigned either numeric or string values.
1 The kind of value a variable holds can change over the life of a
1 program.  By default, variables are initialized to the empty string,
1 which is zero if converted to a number.  There is no need to explicitly
1 initialize a variable in 'awk', which is what you would do in C and in
1 most other traditional languages.
1