Using Multi Array

  • Follow


Hi All

I have tab files. This is UAT result

System : AIX 5.3 gawk 3.1.3

Field[1] = Item code
Field[3] = Tester, User Name
Field[9] = testing result. Pass , Fail, TBA, WI , [other code],,, etc


Input File
A0 .. user1  ..  Pass
A1 .. user1  .. Pass
A2 .. user2 ..  Fail
A3 .. user1  .. TBA
A4 .. user3 ..  WI
.....
Base on Field 1 , 3 , 9 report as below

Item = How many item tested by User

Order Placed By   Item      Pass   Fail     TBA   WI  [Other
Code]  ..... Waiting Test Order
----------------    ----------  -----      -----      -----  -----
user1            3          2          0           1    0
user2            1          0          1           0    0
user3            1          0          0           0    1
......

I try multi Array, The result is not good. May be first time using
Multi Array is the good for me.

Also when using  asort , What is wrong for below ?

  k = asort(user)

        for (i =1 ; i < k ; i++ ) {
            e = user[i]
            ....
        }

Any suggestion ?

My current code as below. This can not handle [other code]

           user[$3]++
           if ( tolower($9) ~ /pass/) {user_pass[$3]++}
           if ( tolower($9) ~ /fail/) {user_fail[$3]++}
           if ( tolower($9) ~ /tba/ ) {user_tba[$3]++}
           if ( tolower($9) ~ /wi/  ) {user_wi[$3]++}
           user_total[$3]++      # Total Item

END {
      fmt01="%-20s %4s %4s %4s %4s %4s %10s\n"
       printf(fmt01,"","","","","","","Waiting")
       printf (fmt01, \
           "Order Placed By","Item","Pass","Fail","TBA","WI","Test
Order")
       printf (fmt01,rep("-",
20),"----","----","----","----","----",rep("-",10))

       a1= 0 ; a2 = 0 ; a3=0 ; a4= 0 ; a5= 0 ; a6 = 0
       #k = asort(user)
       for ( e in user) {
       # for (i =1 ; i < k ; i++ ) {
       #     e = user[i]
           if ( e != "" ) {
           a61 = user_total[e] - user_pass[e] - user_fail[e] -
user_tba[e] - user_wi[e]
           printf(fmt01, \
               e ,
user_total[e],user_pass[e],user_fail[e],user_tba[e],user_wi[e], a61)
           a1 += user_total[e]
           a2 += user_pass[e]
           a3 += user_fail[e]
           a4 += user_tba[e]
           a5 += user_wi[e]
           a6 += a61
          }
       }


}

function rep(s,n,    t) {
   while (n-- > 0 )
       t = t s
   return t






0
Reply moonhkt (146) 3/10/2012 5:04:41 PM

moonhkt <moonhkt@gmail.com> wrote:

> Hi All
> 
> I have tab files. This is UAT result
> 
> System : AIX 5.3 gawk 3.1.3
> 
> Field[1] = Item code
> Field[3] = Tester, User Name
> Field[9] = testing result. Pass , Fail, TBA, WI , [other code],,, etc
> 
> 
> Input File
> A0 .. user1  ..  Pass
> A1 .. user1  .. Pass
> A2 .. user2 ..  Fail
> A3 .. user1  .. TBA
> A4 .. user3 ..  WI
> .....
> Base on Field 1 , 3 , 9 report as below
> 
> Item = How many item tested by User
> 
> Order Placed By   Item      Pass   Fail     TBA   WI  [Other
> Code]  ..... Waiting Test Order
> ----------------    ----------  -----      -----      -----  -----
> user1            3          2          0           1    0
> user2            1          0          1           0    0
> user3            1          0          0           0    1
> ......
> 
> I try multi Array, The result is not good. May be first time using
> Multi Array is the good for me.
> 
> Also when using  asort , What is wrong for below ?
> 
>   k = asort(user)
> 
>         for (i =1 ; i < k ; i++ ) {
>             e = user[i]
>             ....
>         }
> 
> Any suggestion ?
> 
> My current code as below. This can not handle [other code]
> 
>            user[$3]++
>            if ( tolower($9) ~ /pass/) {user_pass[$3]++}
>            if ( tolower($9) ~ /fail/) {user_fail[$3]++}
>            if ( tolower($9) ~ /tba/ ) {user_tba[$3]++}
>            if ( tolower($9) ~ /wi/  ) {user_wi[$3]++}
>            user_total[$3]++      # Total Item
> 
> END {
>       fmt01="%-20s %4s %4s %4s %4s %4s %10s\n"
>        printf(fmt01,"","","","","","","Waiting")
>        printf (fmt01, \
>            "Order Placed By","Item","Pass","Fail","TBA","WI","Test
> Order")
>        printf (fmt01,rep("-",
> 20),"----","----","----","----","----",rep("-",10))
> 
>        a1= 0 ; a2 = 0 ; a3=0 ; a4= 0 ; a5= 0 ; a6 = 0
>        #k = asort(user)
>        for ( e in user) {
>        # for (i =1 ; i < k ; i++ ) {
>        #     e = user[i]
>            if ( e != "" ) {
>            a61 = user_total[e] - user_pass[e] - user_fail[e] -
> user_tba[e] - user_wi[e]
>            printf(fmt01, \
>                e ,
> user_total[e],user_pass[e],user_fail[e],user_tba[e],user_wi[e], a61)
>            a1 += user_total[e]
>            a2 += user_pass[e]
>            a3 += user_fail[e]
>            a4 += user_tba[e]
>            a5 += user_wi[e]
>            a6 += a61
>           }
>        }
> 
> 
> }
> 
> function rep(s,n,    t) {
>    while (n-- > 0 )
>        t = t s
>    return t
> 

Anyone else feel kinda bad that this post presumably sparked the whole
"how do you sort multi-D arrays" discussion but it itself never got
addressed?

On the other hand, the OP could have taken a few minutes to write a small
script that just demonstrates their problem without all the extraneous
code and line-wrapping so we wouldn't have to work nearly so hard to
figure out what his question is, so I guess I don't feel too bad about it.

      Ed.












Posted using www.webuse.net 
0
Reply mortonspam (827) 3/20/2012 2:28:45 PM


1 Replies
97 Views

(page loaded in 0.045 seconds)

Similiar Articles:













7/22/2012 5:24:18 PM


Reply: