summaryrefslogtreecommitdiffstats
path: root/contrib/awk/awklib/eg/prog/wordfreq.awk
blob: b67fed472fb3422d59985911876cc30edd98d585 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
# Print list of word frequencies
{
    $0 = tolower($0)    # remove case distinctions
    gsub(/[^a-z0-9_ \t]/, "", $0)  # remove punctuation
    for (i = 1; i <= NF; i++)
        freq[$i]++
}
END {
    sort = "sort +1 -nr"
    for (word in freq)
        printf "%s\t%d\n", word, freq[word] | sort
    close(sort)
}
OpenPOWER on IntegriCloud