www.delorie.com/gnu/docs/gawk/gawk_119.html   search  
Buy the book!

The GNU Awk User's Guide

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

8. Arrays in awk

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 describes how awk simulates multidimensional arrays, as well as some of the less obvious points about array usage. The chapter finishes with a discussion of gawk's facility for sorting an array based on its indices.

awk maintains a single set of names that may be used for naming variables, arrays, and functions (see section User-Defined Functions). Thus, you cannot have a variable and an array with the same name in the same awk program.

8.1 Introduction to Arrays  
8.2 Referring to an Array Element  How to examine one element of an array.
8.3 Assigning Array Elements  How to change an element of an array.
8.4 Basic Array Example  Basic Example of an Array
8.5 Scanning All Elements of an Array  A variation of the for statement. It loops through the indices of an array's existing elements.
8.6 The delete Statement  The delete statement removes an element from an array.
8.7 Using Numbers to Subscript Arrays  How to use numbers as subscripts in
8.8 Using Uninitialized Variables as Subscripts  Using Uninitialized variables as subscripts.
8.9 Multidimensional Arrays  Emulating multidimensional arrays in
8.10 Scanning Multidimensional Arrays  Scanning multidimensional arrays.
8.11 Sorting Array Values and Indices with gawk  Sorting array values and indices.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003