saving values in file in an array in awk

hi i am trying to save values in a file in an array in awk..the file is as follows:

0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,

so far i have this:

awk 'BEGIN {RS="\n";FS=","}
{
for(i=1;i<=NR;i++)
{
for(j=1;j<=NF;j++)
{
 a[i,j]=$j;
}
}
}
END {
for(i=1;i<=NR;i++)
{
for(j=1;j<=NF;j++)
{
printf("%c\n",a[i,j]);
}
}
}' try > try1

however, i am not getting anything in the try1 file. what am i doing wrong? thanks

You don't need to do a for loop to loop through the records, because awk itself will automatically read every line of the input file and execute the code between { ... } on those lines. Also you do not need to set the RS to \n because that is the default record separator anyway. So this should be sufficient:

awk '
        BEGIN { FS="," }
        {
                for(j=1;j<=NF;j++) {
                         a[NR,j]=$j;
                }
        }
        END {
                for(i=1;i<=NR;i++) {
                        for(j=1;j<=NF;j++) {
                                printf("%d\n",a[i,j]);
                        }
                }
        }
' try > try1

Also note that I changed %c to %d. %c would print the character whose ascii code is 0, which is a null character, probably the main reason your output file looked empty.

thanks a lot for your help.. that worked perfect.. just one last question.. is there a quick and dirty way to get rid of the last comma in the last column? since my FS is a comma it is picking up an extra column after the last column..

Well, you could just use <NF instead of <=NF to ignore the final field... is that what you want?

yup, got it..dunno what i was thinking that was easy..thanks a lot for your help..