Skip to content

Instantly share code, notes, and snippets.

@adsharma
Created January 16, 2022 18:37
Show Gist options
  • Save adsharma/4df62f866093ef7f8f3c6e673a0e9cd8 to your computer and use it in GitHub Desktop.
Save adsharma/4df62f866093ef7f8f3c6e673a0e9cd8 to your computer and use it in GitHub Desktop.
BEGIN { LETTERS = "abcdefghijklmnopqrstuvwxyz" }
{
len = length($0);
if (len == 5) {
for (i = 1; i <= len; i++) {
c = substr($0, i, 1);
ltr = index(LETTERS, c);
if (ltr > 0) {
++count[ltr];
}
}
}
}
END {
for (i = 1; i <= 26; i++) {
c = substr(LETTERS, i, 1);
print(c, count[i])
}
}
# cat /usr/share/dict/words | awk -f /tmp/count.awk | sort -k2,2rn
#
# a 5634
# e 4844
# r 3508
# o 3277
# i 3258
# n 2726
# l 2713
# s 2710
# t 2636
# u 2271
# y 1836
# c 1724
# d 1598
# h 1534
# m 1498
# p 1385
# b 1271
# g 1228
# k 1015
# w 722
# f 696
# v 514
# z 294
# x 232
# j 198
# q 95
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment