统计词频

用shell处理以下内容

1、按单词出现频率降序排序!

2、按字母出现频率降序排序!

the squid project provides a number of resources toassist users design,implement and support squid installations. Please browsethe documentation and support sections for more infomation

1. 按单词出现频率降序排序

解决思路:把空格换为换行符,之后统计重复的次数,最后根据重复次数排序

cat test |sed 's# #\n#g' |sort| uniq -c | sort -nr

uniq:

-c 输出重复次数

sort:

-n 按照数值比较排序

-r 逆序输出结果

2. 按字母出现频率降序排序

cat test | grep -o "[a-zA-Z]" | sort | uniq -c | sort -nr

grep -o --only-matching:
Show only the part of a matching line that matches PATTERN

posted @ 2018-10-11 16:50  徐~某~某  阅读(139)  评论(0编辑  收藏  举报