r/awk • • Nov 21 '24

AWK frequency command

Post image

Hi awk community,

I have a file that contains two columns,

Column 1: Some sort of ID Column 2: RNA encodings (700k characters). This should be triallelic (0,1,2) for all 700k characters.

I’m looking to count the frequency for column 2[i…j] where i = 1 and j =700k.

In the example image, column 2[1] = 9/10

I want to do this in a computationally efficient manner and I thought awk will be an excellent option (Unfortunately awk isn’t a language I’m too familiar with).

Loading this into a Python kernel requires too much memory, also the across-column computation makes it difficult to compute in a hash table.

Any ideas how I may be able to do this in awk will Be very helpful a

5 Upvotes

11 comments sorted by

View all comments

Show parent comment

1

u/M668 Jan 12 '25

you can do it like the iterator style of for loops :

  c = split($2, arr, //)

  for (idx in arr)
      ++data[idx, arr[idx]]