I want to count the number of 1s and 2s in each population ignoring 0s if there is any but printing 0 if there is no 1 or 2 and have an output like this:
4 0 2 2
1 3 1 1
Where 4 0 is the number of "1s" and "2s" in the second column of the first population. 1 3 is the number of "1s" and "2s" in the third column of the first population and so on.
Thank you but I tried it on the test file as I have posted above and it is extremely slow, it has not finished calculating yet so it should take even longer for my real big file. I have a code as follows myself:
{
for (i=2; i<=NF; i++)
if ($i=="1") c_one++
else if ($i=="2") c_two++}
END{
for(i=2; i<=NF; i++)
printf ("%d " " %d\n", c_one, c_two)
}
But this is for the case of having my populations separated that is ABO in one file and GPO in the other. Maybe this code can be modified for the new file for the populations together.
---------- Post updated at 09:00 AM ---------- Previous update was at 08:53 AM ----------
sorry, I had made a mistake. it is not slow but it gives me these numbers:
That works, thanks a lot. I am so sorry but I have a problem because my original file is composed of 47 populations. The script works well for the test file but when I run it on my original file, it gives me 4 columns while it should give me 47*2 columns. I am sorry for my basic questions.