I have a text file that looks like this:
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. There is a fair bit of documentation on doing this by field, but not by row. I have been thinking something like:
for(i=1; i <= NF, i++) to loop through the columns in each row and then make a counter variable to add occurrences to. Is there a simpler way to do this?
In awk, I don’t think there is a simpler way to iterate over the fields in a line.
Given your input, this outputs