Subject: Re: text processing tool
To: Antti Kantee <pooka@cs.hut.fi>
From: Perry E. Metzger <perry@piermont.com>
List: netbsd-help
Date: 03/12/2003 14:11:10
Antti Kantee <pooka@cs.hut.fi> writes:
> On Wed Mar 12 2003 at 10:24:02 -0500, Perry E. Metzger wrote:
> > and then printing it out in the other order. Awk only has 1D arrays I
> > believe.
>
> Not true:
>
> brain-damage:6:~> echo 'a b'|awk '{a[1,1]=$1;a[1,2]=$2}END{print a[1,1],a[1,2]}'
> a b
Ah! Reading the manual, I find that although the arrays are 1D, you
can simulate more with the wacky concatenation facility:
Arrays
Arrays are subscripted with an expression between square
brackets ([ and ]). If the expression is an expression
list (expr, expr ...) then the array subscript is a
string consisting of the concatenation of the (string)
value of each expression, separated by the value of the
SUBSEP variable. This facility is used to simulate multi-
ply dimensioned arrays. For example:
i = "A"; j = "B"; k = "C"
x[i, j, k] = "hello, world\n"
--
Perry E. Metzger perry@piermont.com