It doesn't look like you've done anything with arrays in your script, but perhaps this will get you started in the direction; it's adapted from Aho, Kernighan and Weinberger
The AWK Programming Language's chapter on arrays in AWK.
AWK provides one-dimensional arrays for storing strings and number; for example, the statement
assigns the current input line to element NR of the array x.
It's possible to read the entire input into an array; this program prints its input in reverse line order:
Code:
{ x[NR] = $0 }
END { for (i = NR; i > 0; i--) print x[i] }
The first action reads the input line in the array
x, using the line number as a subscript; the read work is done in the
END statement. To start are the first line of input and go to the last, you would revers the
for tests.
You can also do multi-dimensional arrays; e.g., they're not supported directly but are simulated using a one-dimensional array:
Code:
for (i = 1; i <= 10; i++)
for (j = 1; j <= 10; j++)
arr[i, j] = 0
this creates an array of 100 elements whose subscripts appear to have the form 1,1, 1,2 and so on. Internally, though, are stored as strings of the form
1 SUBSEP 1,
1 SUBSEP 2, and so on. The built-in variable
SUBSEP contains the value of the subscript-component separator; its default value is not a comma but "\034", a value unlikely to appear in normal text.
The test for array membership with multidimensional subscripts uses a parenthesized list of subscripts, such as
Code:
if ((i,j) in arr) ...
To loop over such an array, you would write
and use split(k,x,SUBSEP) if access to the individual subscript components is needed.
You don't need to declare an array, it will spring into existence by mentioning it (as with variables).
Hope this helps some.