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

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

游戏|数码彩彩2024-04-06 7:44:21337A+A-

今天主要分享一个用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
如何用shell脚本实现单词及字母去重排序?

 

执行结果:

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

 


如何用shell脚本实现单词及字母去重排序?
点击这里复制本文地址 版权声明:本文内容由网友提供,该文观点仅代表作者本人。本站(https://www.angyang.net.cn)仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

昂扬百科 © All Rights Reserved.  渝ICP备2023000803号-3网赚杂谈