Count the number of occurrences of each letter by row

Friday, December 28, 2012 0 Comments


A A A G A A
A A A A A A
G A G A G G
A G G G G G
G A A A A A
T C T C C C
A A A G A A
C C C C C C
T G G G G G
T T T T T T
I want to count the number of occurrences of each letter by row.

solution
---------
awk '{
delete a
for (i=1; i<=NF; i++)
a[$i]++
printf("%d -- ", NR)
for (val in a)
printf("%s:%d, ", val, a[val])
print ""
}'

0 comments: