An array is a table of values called elements. The elements of an array are distinguished by their indices. Indices may be either numbers or strings.
This chapter describes how arrays work in
awk, how to use array elements, how to scan
through every element in an array, and how to remove array elements. It also
multidimensional arrays, as well as some of the less obvious points about
array usage. The chapter moves on to discuss
gawk’s facility for sorting arrays, and ends with
a brief description of
gawk’s ability to
support true arrays of arrays.
This section presents the basics: working with elements in arrays one at a time, and traversing all of the elements in an array.
Doing linear scans over an associative array is like trying to club someone to death with a loaded Uzi.
awk language provides
one-dimensional arrays for storing groups of related strings or numbers.
awk array must
have a name. Array names have the same syntax as variable names; any
valid variable name would also be a valid array name. But one name
cannot be used in both ways (as an array and as a variable) in the same
resemble arrays in other programming languages, but there are
fundamental differences. In
awk, it isn’t necessary to specify the size of an array before starting to use it. Additionally, any number or string, not just consecutive integers, may be ...