Counting occurences in column

Hi guys!

I have a problem writing script that would convert this input

into this output:

I have an awk script that counts occurences of a sign in a column, but don't know how to change it so that I would give me desired output.

script

awk '{count[$1]++}END{for(j in count) print j";"count[j]""}' FS=: file.csv

I would appreciate any help!

Cheers,
grincz!

Assuming no empty field/line in the input, try:

awk -F\; '{for(i=1;i<=NF;i++) count[$i,i]++;if(max<NF) max=NF}
END{for(i=65;i<=90;i++) {
c=sprintf("%c",i);
printf("%s",c);
for(j=1;j<=max;j++)
 printf("\t%d",count[c,j])
print ""
}
printf ("sum\t%d\t%d\t%d\t%d\t%d",NR,NR,NR,NR,NR)
}' file
1 Like

Works just great! Thanks a lot!