如何用shell脚本实现单词及字母去重排序?

今天主要分享一个用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

 

执行结果:

 


胜象大百科