[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] I have a problem with gawk and "for in do done" loop
From: |
arnold |
Subject: |
Re: [bug-gawk] I have a problem with gawk and "for in do done" loop |
Date: |
Thu, 27 Sep 2012 01:57:51 -0600 |
User-agent: |
Heirloom mailx 12.4 7/29/08 |
Hello.
Nguyen Ngoc Anh <address@hidden> wrote:
> I am new to using gawk in my job. I want to use "for in do done" loop and i
> have the following scripts:
>
> for fn in a b d e f
> do
> echo $fn
> done
>
> this code is not working ( I am using Windows 7), and I really want use it
> in my job. Can you help me ?
> Thanhs,
This syntax is for shell scripts, not awk scripts. In awk, you first
set up an array:
a["one"] = 1
a["two"] = 2
a[3] = "three"
...
Then you can loop over every element in the array as follows:
for (i in a)
printf("a[%s] = %s\n", i, a[i])
I suggest that you read the gawk documentation, which is available online
at http://www.gnu.org/software/gawk/manual/
Arnold