Looping through a list of arrays

Looping through a list of arrays

am 12.10.2007 14:42:53 von Noatec

comp.unix.shell forgive me for I have sinned.
Its been 3 months since my last post.

How would one loop through a list of arrays in ksh93 ?
Background:
I'm grabbing 10 rows off the DB at a time and loading a large array
Then splitting the large array into 10 small ones, each containing the
five values in that row. If this is completely unnecessary, feel free
to take me to school.

#!/usr/bin/ksh93
set -A BIGONE `db2 select statement`

NUMELEM=${#BIGONE[*]}

ROW=0
until (( $ROW > $NUMELEM ))
do
NUM=$((ROW/5))
set -A SMALL$NUM ${BIGONE[*]:$ROW:5}
((ROW+=5))
print ${SMALL$NUM[*]} <= This is what I thought would work.
done

I feel like I'm missing something key.
Thanks in advance.
Roger

Re: Looping through a list of arrays

am 12.10.2007 14:59:55 von Ed Morton

Noatec wrote:
> comp.unix.shell forgive me for I have sinned.
> Its been 3 months since my last post.
>
> How would one loop through a list of arrays in ksh93 ?
> Background:
> I'm grabbing 10 rows off the DB at a time and loading a large array
> Then splitting the large array into 10 small ones, each containing the
> five values in that row. If this is completely unnecessary, feel free
> to take me to school.

You should be using awk. The 10 "rows" will automatically be treated as
10 "records", each stored in $0, and the 5 values in each "row" will
automatically be the 5 "fields" $1->$5
>
> #!/usr/bin/ksh93
> set -A BIGONE `db2 select statement`

Without knowing what the output of "db2 select statement" looks like, I
can't be more specific, but try this:

db2 select statement |
awk '{
printf "NR=%d; NF=%d; $0=%s\n",NR,NF,$0
for (i=1;i<=NF;i++) {
printf "\t%d:%s\n",i,$i
}
}'

and you'll see what I mean sbout the records and fields then you can
tell us what you want to do with them if you need more help.

Regards,

Ed.

Re: Looping through a list of arrays

am 12.10.2007 15:25:35 von Noatec

The output looks like:
CPID DATE PRI APPGRP APPNAME FILENAME STATUS
1234 1192194770 01 appgroupa appname1 some.big.long.filename.rpt

Here's a single record from your awk statement from my test DB.
NR=1; NF=5; $0=00 1191964262 CHECKIMAGEBW CHECKIMAGE
CBIP.PEP000RP.STEP4A.
0004.2007282.13515641426.ARD
1:00
2:1191964262
3:CHECKIMAGEBW
4:CHECKIMAGE
5:CBIP.PEP000RP.STEP4A.0004.2007282.13515641426.ARD

I get this, but I'm not sure how it would work with what I'm trying to
do.
Maybe I should explain that a little better. Each row in this DB
represents a load I need to issue in our imaging environment. This
script will be the "dispatcher". Rather than single thread this, I was
getting fancy and trying to reduce the number of selects by getting 10
rows at a time. Once I have the 10 rows I need to use the elements of
each row to issue the load requests. I know what your thinking, but my
boss wont let me write it in perl because only me and one other person
on our team knows it. Maybe he knows something we don't.
Thanks


On Oct 12, 7:59 am, Ed Morton wrote:
> Noatec wrote:
> > comp.unix.shell forgive me for I have sinned.
> > Its been 3 months since my last post.
>
> > How would one loop through a list of arrays in ksh93 ?
> > Background:
> > I'm grabbing 10 rows off the DB at a time and loading a large array
> > Then splitting the large array into 10 small ones, each containing the
> > five values in that row. If this is completely unnecessary, feel free
> > to take me to school.
>
> You should be using awk. The 10 "rows" will automatically be treated as
> 10 "records", each stored in $0, and the 5 values in each "row" will
> automatically be the 5 "fields" $1->$5
>
>
>
> > #!/usr/bin/ksh93
> > set -A BIGONE `db2 select statement`
>
> Without knowing what the output of "db2 select statement" looks like, I
> can't be more specific, but try this:
>
> db2 select statement |
> awk '{
> printf "NR=%d; NF=%d; $0=%s\n",NR,NF,$0
> for (i=1;i<=NF;i++) {
> printf "\t%d:%s\n",i,$i
> }
>
> }'
>
> and you'll see what I mean sbout the records and fields then you can
> tell us what you want to do with them if you need more help.
>
> Regards,
>
> Ed.

Re: Looping through a list of arrays

am 12.10.2007 17:40:43 von Ed Morton

Noatec wrote:

[ please don't top-post, fixed below ]


> On Oct 12, 7:59 am, Ed Morton wrote:
>
>>Noatec wrote:
>>
>>>comp.unix.shell forgive me for I have sinned.
>>>Its been 3 months since my last post.
>>
>>>How would one loop through a list of arrays in ksh93 ?
>>>Background:
>>>I'm grabbing 10 rows off the DB at a time and loading a large array
>>>Then splitting the large array into 10 small ones, each containing the
>>>five values in that row. If this is completely unnecessary, feel free
>>>to take me to school.
>>
>>You should be using awk. The 10 "rows" will automatically be treated as
>>10 "records", each stored in $0, and the 5 values in each "row" will
>>automatically be the 5 "fields" $1->$5
>>
>>
>>
>>
>>>#!/usr/bin/ksh93
>>>set -A BIGONE `db2 select statement`
>>
>>Without knowing what the output of "db2 select statement" looks like, I
>>can't be more specific, but try this:
>>
>>db2 select statement |
>>awk '{
>> printf "NR=%d; NF=%d; $0=%s\n",NR,NF,$0
>> for (i=1;i<=NF;i++) {
>> printf "\t%d:%s\n",i,$i
>> }
>>
>>}'
>>
>>and you'll see what I mean sbout the records and fields then you can
>>tell us what you want to do with them if you need more help.
>>
>>Regards,
>>
>> Ed.
>
> The output looks like:
> CPID DATE PRI APPGRP APPNAME FILENAME STATUS
> 1234 1192194770 01 appgroupa appname1 some.big.long.filename.rpt
>
> Here's a single record from your awk statement from my test DB.
> NR=1; NF=5; $0=00 1191964262 CHECKIMAGEBW CHECKIMAGE
> CBIP.PEP000RP.STEP4A.
> 0004.2007282.13515641426.ARD
> 1:00
> 2:1191964262
> 3:CHECKIMAGEBW
> 4:CHECKIMAGE
> 5:CBIP.PEP000RP.STEP4A.0004.2007282.13515641426.ARD
>
> I get this, but I'm not sure how it would work with what I'm trying to
> do.
> Maybe I should explain that a little better. Each row in this DB
> represents a load I need to issue in our imaging environment. This
> script will be the "dispatcher". Rather than single thread this, I was
> getting fancy and trying to reduce the number of selects by getting 10
> rows at a time. Once I have the 10 rows I need to use the elements of
> each row to issue the load requests.

OK, then how do you "issue a load request"? Show a couple of lines of
input and the "issue a load request" commands you'd want executed given
that input.

> I know what your thinking, but my
> boss wont let me write it in perl because only me and one other person
> on our team knows it. Maybe he knows something we don't.

Apparently you don't know what I'm thinking as I'd never suggest writing
anything in perl ;-). I'm sure it has some fine and appropriate
applications, I've just never personally come across one.

Ed.

Re: Looping through a list of arrays

am 12.10.2007 19:52:21 von Maxwell Lol

Noatec writes:

> comp.unix.shell forgive me for I have sinned.
> Its been 3 months since my last post.

(everyone) Hi, Noatec!

Re: Looping through a list of arrays

am 12.10.2007 20:43:43 von Noatec

On Oct 12, 10:40 am, Ed Morton wrote:
> Noatec wrote:
>
> [ please don't top-post, fixed below ]
>
>
>
> > On Oct 12, 7:59 am, Ed Morton wrote:
>
> >>Noatec wrote:
>
> >>>comp.unix.shell forgive me for I have sinned.
> >>>Its been 3 months since my last post.
>
> >>>How would one loop through a list of arrays in ksh93 ?
> >>>Background:
> >>>I'm grabbing 10 rows off the DB at a time and loading a large array
> >>>Then splitting the large array into 10 small ones, each containing the
> >>>five values in that row. If this is completely unnecessary, feel free
> >>>to take me to school.
>
> >>You should be using awk. The 10 "rows" will automatically be treated as
> >>10 "records", each stored in $0, and the 5 values in each "row" will
> >>automatically be the 5 "fields" $1->$5
>
> >>>#!/usr/bin/ksh93
> >>>set -A BIGONE `db2 select statement`
>
> >>Without knowing what the output of "db2 select statement" looks like, I
> >>can't be more specific, but try this:
>
> >>db2 select statement |
> >>awk '{
> >> printf "NR=%d; NF=%d; $0=%s\n",NR,NF,$0
> >> for (i=1;i<=NF;i++) {
> >> printf "\t%d:%s\n",i,$i
> >> }
>
> >>}'
>
> >>and you'll see what I mean sbout the records and fields then you can
> >>tell us what you want to do with them if you need more help.
>
> >>Regards,
>
> >> Ed.
>
> > The output looks like:
> > CPID DATE PRI APPGRP APPNAME FILENAME STATUS
> > 1234 1192194770 01 appgroupa appname1 some.big.long.filename.rpt
>
> > Here's a single record from your awk statement from my test DB.
> > NR=1; NF=5; $0=00 1191964262 CHECKIMAGEBW CHECKIMAGE
> > CBIP.PEP000RP.STEP4A.
> > 0004.2007282.13515641426.ARD
> > 1:00
> > 2:1191964262
> > 3:CHECKIMAGEBW
> > 4:CHECKIMAGE
> > 5:CBIP.PEP000RP.STEP4A.0004.2007282.13515641426.ARD
>
> > I get this, but I'm not sure how it would work with what I'm trying to
> > do.
> > Maybe I should explain that a little better. Each row in this DB
> > represents a load I need to issue in our imaging environment. This
> > script will be the "dispatcher". Rather than single thread this, I was
> > getting fancy and trying to reduce the number of selects by getting 10
> > rows at a time. Once I have the 10 rows I need to use the elements of
> > each row to issue the load requests.
>
> OK, then how do you "issue a load request"? Show a couple of lines of
> input and the "issue a load request" commands you'd want executed given
> that input.
>
> > I know what your thinking, but my
> > boss wont let me write it in perl because only me and one other person
> > on our team knows it. Maybe he knows something we don't.
>
> Apparently you don't know what I'm thinking as I'd never suggest writing
> anything in perl ;-). I'm sure it has some fine and appropriate
> applications, I've just never personally come across one.
>
> Ed.
Sorry about the top post.
To issue a load request I pass APPGRP APPNAME and FILENAME as args to
a program called arsload.
So, for the above data sample It would look like:
arsload -n -I archive -g CHECKIMAGEGS -a CHECKIMAGE -c /arsload -fv -u
admin -p password\ CBIP.PEP000RP.STEP4A.0004.2007282.13515641426.ARD
The idea being, issue 0-10 of the loads I got from the DB depending on
some system load checking I was planing on doing.

Re: Looping through a list of arrays

am 12.10.2007 21:40:23 von Ed Morton

Noatec wrote:
> On Oct 12, 10:40 am, Ed Morton wrote:
>
>>Noatec wrote:
>>
>>[ please don't top-post, fixed below ]
>>
>>
>>
>>
>>>On Oct 12, 7:59 am, Ed Morton wrote:
>>
>>>>Noatec wrote:
>>
>>>>>comp.unix.shell forgive me for I have sinned.
>>>>>Its been 3 months since my last post.
>>
>>>>>How would one loop through a list of arrays in ksh93 ?
>>>>>Background:
>>>>>I'm grabbing 10 rows off the DB at a time and loading a large array
>>>>>Then splitting the large array into 10 small ones, each containing the
>>>>>five values in that row. If this is completely unnecessary, feel free
>>>>>to take me to school.
>>
>>>>You should be using awk. The 10 "rows" will automatically be treated as
>>>>10 "records", each stored in $0, and the 5 values in each "row" will
>>>>automatically be the 5 "fields" $1->$5
>>
>>>>>#!/usr/bin/ksh93
>>>>>set -A BIGONE `db2 select statement`
>>
>>>>Without knowing what the output of "db2 select statement" looks like, I
>>>>can't be more specific, but try this:
>>
>>>>db2 select statement |
>>>>awk '{
>>>> printf "NR=%d; NF=%d; $0=%s\n",NR,NF,$0
>>>> for (i=1;i<=NF;i++) {
>>>> printf "\t%d:%s\n",i,$i
>>>> }
>>
>>>>}'
>>
>>>>and you'll see what I mean sbout the records and fields then you can
>>>>tell us what you want to do with them if you need more help.
>>
>>>>Regards,
>>
>>>> Ed.
>>
>>>The output looks like:
>>>CPID DATE PRI APPGRP APPNAME FILENAME STATUS
>>>1234 1192194770 01 appgroupa appname1 some.big.long.filename.rpt
>>
>>>Here's a single record from your awk statement from my test DB.
>>>NR=1; NF=5; $0=00 1191964262 CHECKIMAGEBW CHECKIMAGE
>>>CBIP.PEP000RP.STEP4A.
>>>0004.2007282.13515641426.ARD
>>> 1:00
>>> 2:1191964262
>>> 3:CHECKIMAGEBW
>>> 4:CHECKIMAGE
>>> 5:CBIP.PEP000RP.STEP4A.0004.2007282.13515641426.ARD

That doesn't make sense. You said the output would have 7 fields:

CPID DATE PRI APPGRP APPNAME FILENAME STATUS

but then you showed 6 fields:

1234 1192194770 01 appgroupa appname1 some.big.long.filename.rpt

and then your real sample only had 5 fields:

00 1191964262 CHECKIMAGEBW CHECKIMAGE
CBIP.PEP000RP.STEP4A.0004.2007282.13515641426.ARD

Please clarify.

>>>I get this, but I'm not sure how it would work with what I'm trying to
>>>do.
>>>Maybe I should explain that a little better. Each row in this DB
>>>represents a load I need to issue in our imaging environment. This
>>>script will be the "dispatcher". Rather than single thread this, I was
>>>getting fancy and trying to reduce the number of selects by getting 10
>>>rows at a time. Once I have the 10 rows I need to use the elements of
>>>each row to issue the load requests.
>>
>>OK, then how do you "issue a load request"? Show a couple of lines of
>>input and the "issue a load request" commands you'd want executed given
>>that input.
>>
>>
>>>I know what your thinking, but my
>>>boss wont let me write it in perl because only me and one other person
>>>on our team knows it. Maybe he knows something we don't.
>>
>>Apparently you don't know what I'm thinking as I'd never suggest writing
>>anything in perl ;-). I'm sure it has some fine and appropriate
>>applications, I've just never personally come across one.
>>
>> Ed.
>
> Sorry about the top post.
> To issue a load request I pass APPGRP APPNAME and FILENAME as args to

So given what you first said earlier:

>>>>The output looks like:
>>>>CPID DATE PRI APPGRP APPNAME FILENAME STATUS

and ignoring the inconsistencies mentioned above in the data you posted,
that means you want to use the 4th, 5th, and 6th fields so I'll use that
below.

> a program called arsload.

Really?

> So, for the above data sample It would look like:
> arsload -n -I archive -g CHECKIMAGEGS -a CHECKIMAGE -c /arsload -fv -u
> admin -p password\ CBIP.PEP000RP.STEP4A.0004.2007282.13515641426.ARD
> The idea being, issue 0-10 of the loads I got from the DB depending on
> some system load checking I was planing on doing.
>

This would produce the commands you want from the first 10 records of
your "db2" output:

db2 select statement |
awk -v start=1 -v end=10 'NR >= start {
printf "arsload -n -I archive -g %s -a %s -c /arsload -fv -u admin
-p password\\ %s\n",$4,$5,$6
} NR==end { exit }'

which you could then "eval" or save in a file to execute, or you could
invoke via awks "system()" call. All you'd need to do then is call awk
as many times as you like, just changing the values of "start" and
"end", or have awk produce all the output then carve it up, or....

It's not really clear if you're intending to call "db2" multiple times
or call it once and then just invoke "arsload" 10 times, then sleep
and/or do your load checking, then invoke "arsload" another 10 times or
do something else...

Ed.