~vcs-imports/gawk/master

« back to all changes in this revision

Viewing changes to awklib/eg/prog/wordfreq.awk

  • Committer: Arnold D. Robbins
  • Date: 2010-07-16 10:09:56 UTC
  • Revision ID: git-v1:bc70de7b3302d5a81515b901cae376b8b51d2004
Tags: gawk-3.1.0
Move to gawk-3.1.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Print list of word frequencies
 
1
# wordfreq.awk --- print list of word frequencies
 
2
 
2
3
{
3
4
    $0 = tolower($0)    # remove case distinctions
4
 
    gsub(/[^a-z0-9_ \t]/, "", $0)  # remove punctuation
 
5
    # remove punctuation
 
6
    gsub(/[^[:alnum:]_[:blank:]]/, "", $0)
5
7
    for (i = 1; i <= NF; i++)
6
8
        freq[$i]++
7
9
}
 
10
 
 
11
END {
 
12
    for (word in freq)
 
13
        printf "%s\t%d\n", word, freq[word]
 
14
}
8
15
END {
9
16
    sort = "sort +1 -nr"
10
17
    for (word in freq)