Awk offers associative indexing for array processing. Elements of 1 dimensional array can be iterated:
e.g.
for(index in arr1)
print "arr1[" index "]=" arr1[index]
But how this kind done for a two dimensional array? Does kind of syntax,given below work?
for(index1 in arr2)
for(index2 in arr2)
arr2[index1,index2]
AWK fakes multidimensional arrays by concatenating the indices with the character held in the SUBSEP variable (0x1c). You can iterate through a two-dimensional array using
splitlike this (based on an example in theinfo gawkfile):Output:
You can, however, iterate over a numerically indexed array using nested for loops:
Another noteworthy bit of information from the GAWK manual:
Gawk 4 adds arrays of arrays. From that link:
Also see Traversing Arrays of Arrays for information about the following function which walks an arbitrarily dimensioned array of arrays, including jagged ones: