1.统计词频:
写一个 bash 脚本以统计一个文本文件 words.txt 中每个单词出现的频率。
为了简单起见,你可以假设:
words.txt只包括小写字母和 ' ' 。
每个单词只由小写字母组成。
单词间由一个或多个空格字符分隔。
the day is sunny the the
the sunny is is
the 4
is 3
sunny 2
day 1
code
cat word.txt | tr -s " " "\n"| sort | uniq -c| sort -r| awk '{print $2, $1}'
过程
(1).cat word txt
(2). cat word.txt | tr -s " " "\n" 空格变换为换行
(3).排序sort
(3).统计词频
(4).统计词频 倒序sort,并awk 打印,