分享一個有趣的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
分享一個有趣的shell腳本--單詞及字母去重排序案例

執行結果:

分享一個有趣的shell腳本--單詞及字母去重排序案例

分享一個有趣的shell腳本--單詞及字母去重排序案例


覺得有用的朋友多幫忙轉發哦!後面會分享更多devops和DBA方面的內容,感興趣的朋友可以關注下~

分享一個有趣的shell腳本--單詞及字母去重排序案例


分享到:


相關文章: