And here is my initial solution in UNIX shell:
# bentley_knuth.sh
# Usage:
# ./bentley_knuth.sh n file
# where "n" is the number of most frequent words
# you want to find in "file".
awk '
{
for (i = 1; i <= NF; i++)
word_freq[$i]++
}
END {
for (i in word_freq)
print i, word_freq[i]
}
' < $2 | sort -nr +1 | sed $1q
So you invoke awk, and then run the output of awk through sort and sed. tr -cs A-Za-z '
' |
tr A-Z a-z |
sort |
uniq -c |
sort -rn |
sed ${1}q
"awk" is generally accepted as a full programming language, whereas "tr", "sort", "uniq", and "sed" are command line utilities. I don't think "awk" classes as a command line utility, so I don't class your solution as "shell". C = (F-30) / 2
F = 2 * C + 30
Exact conversions: C = (F-32) * 5 / 9
F = C / 5 * 9 + 32
Table: C F
-40 -40
0 32 (Approx water freezing point)
10 50
20 68 ( ~ 70)
~21 70
30 86
37 98.6 (body temperature)
40 104
50 122
... ...
100 212 (Approx water boiling point)
https://news.ycombinator.com/item?id=19980584