Skip to content

Instantly share code, notes, and snippets.

@bonifazi
Created June 29, 2023 14:54
Show Gist options
  • Save bonifazi/fb7cb5ec95e92759b8b4cb13e55ad31c to your computer and use it in GitHub Desktop.
Save bonifazi/fb7cb5ec95e92759b8b4cb13e55ad31c to your computer and use it in GitHub Desktop.
Count 0,1,2,5 per animal genotypes
awk 'BEGIN {
OFS = ","
print "ID", 0, 1, 2, 5
}
{
for (i = 2; i <= NF; i++) {
count[$1,$i]++
}
vals[$1] = $1
}
END {
for (id in vals) {
print id, count[id, 0]+0, count[id, 1]+0, count[id, 2]+0, count[id, 5]+0
}
}' data.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment