今天主要分享一個用shell腳本來實現單詞及字母去重排序案例,下面一起來看下吧~
需求
1、按單詞出現頻率降序排序!
2、按字母出現頻率降序排序!
相關文本:
the squid project provides a number ofresources to assist users design implement and support squid installations. Please browse the documentation and support sections for more infomation byoldboy training
實現腳本:
#!/bin/bash ################################################ # File Name: abc.sh ################################################ ? a="the squid project provides a number ofresources to assist users design implement and support squid installations.Please browse the documentation and support sections for more infomation byoldboy training" ? echo "按單詞出現頻率降序排序!" for i in $a do echo $i done| sort |uniq -c|sort -nk1 -r echo "按字母出現頻率降序排序!" echo $a |grep -o "[a-z]" |sort|uniq -c |sort -nk1 -r
執行結果: