单词出现频率降序排序!

来源:互联网 发布:川岛芳子 方姥 知乎 编辑:程序博客网 时间:2024/05/16 14:56

用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

str="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" function word() {echo $str |sed 's#[^a-zA-Z]#\n#g'|grep -v "^$"|sort|uniq -c|sort -rn -k1} function string() {echo $str |grep -o "."|egrep -v " |^$|[^a-zA-Z]"|sort|uniq -c|sort -rn -k1}        case $1 in         word)         word         ;;        string)         string         ;;        *)          echo "arg {word | string}"        esac
0 0
原创粉丝点击