概述
今天主要分享一个用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 -recho "按字母出现频率降序排序!"echo $a |grep -o "[a-z]" |sort|uniq -c |sort -nk1 -r
![e49cd0319780bf7d9b4bf488906fcc35.png](https://img-blog.csdnimg.cn/img_convert/e49cd0319780bf7d9b4bf488906fcc35.png)
执行结果:
![7da9c667cd5cffe694753481fafbb113.png](https://img-blog.csdnimg.cn/img_convert/7da9c667cd5cffe694753481fafbb113.png)
![ea3db05386ab9532040fbcf1677360af.png](https://img-blog.csdnimg.cn/img_convert/ea3db05386ab9532040fbcf1677360af.png)
觉得有用的朋友多帮忙转发哦!后面会分享更多devops和DBA方面的内容,感兴趣的朋友可以关注下~
![ed13683eab179b5bd8cc057d86a4def7.gif](https://img-blog.csdnimg.cn/img_convert/ed13683eab179b5bd8cc057d86a4def7.gif)