comparing variables in awk array

Hi,

I am trying to sort and display the below(like) input using awk command:

Input:
------
0;A
4;A
5;A
33;A
45;A
0;B
4;B
5;B
33;B
45;B

Output (desired):
-------

A 0;4;5;33;45
B 0;4;5;33;45

I am using awk -F\; 'END { for (k in arr) print k FS arr[k] }{ arr[$2] = arr[$2] ? arr[$2] FS $1 : $1 }' file name to get the output. the output which i get after runnin this command is

A ;4;5;33;45 -- '0' is missing
B ;4;5;33;45 -- '0' is missing

i think awk is not displaying 0 for the first time when it compares it with the next element in the array.

Can any one of you help me out to find the solution for this.

so you are sorting the file first then giving it to the awk???

yes..the input which i have given is the sorted one...

then this will do ..

awk -F";" '{A[$2]=A[$2]$1FS}END{for(i in A){print i" "A}}' filename

It is wierd!

This also seems to work:

awk -F\; 'END { for (k in arr) print k FS arr[k] }{ arr[$2] = arr[$2] ? arr[$2] FS $1 : $1 "" }' 

Seems awk sees the first zero and does "something". Turning the 0 into a string ($1 "") unconfuses it.

I'm sure it's not a bug, but it's odd behaviour.

Thanks Vidyadhar... Its working.. Can you explain me if you have any idea what was the problem in the command that i have used. it was not displaying or comparing only 0.