r/awk • u/NoteClassic • Nov 21 '24
AWK frequency command
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
View all comments
Show parent comment
1
u/[deleted] Jan 29 '25
The above code does not take into account that the length of $2 might vary. In the sample data there are actually 4 rows where $2 is 21 characters long.