排序的字符串如下: the squid project provides a number of resources toassist users design,implement and support squid installations. Please browsethe documentation and support

此题目有多种解法,sed、awk、tr等等,都可以解决此题,命令运用灵活多变。

编写shell脚本

解法1:

#!/bin/bash

###-------------CopyRight-------------
# Name:sort string
# Version Number:1.0
# Type:sh
# Language:bash shell
# Date:--
# Author:sandy
# QQ:
# Email:eeexu123@.com str="the squid project provides a number of resources toassist users design,implement and support squid installations. Please browsethe documentation and support sections for more infomation"
#no1按单词出现的频率降序排序
word(){
echo $str|sed 's#[^a-zA-Z]#\n#g'|grep -v "^$"|sort|uniq -c|sort -rn -k1
} #no2按字母出现的频率降序排序
string(){
echo $str|grep -o "."|egrep -v "[^a-zA-Z]"|sort|uniq -c|sort -rn -k1
} menu(){
cat <<END
.按单词出现的频率降序排序
.按字母出现的频率降序排序
END
read -p "Pls you choose num:" num
}
menu usage(){
echo "USAGE:You muset choose 1 or 2"
exit
} case "$num" in
)
word
;;
)
string
;;
*)
usage
esac

解法2:

#!/bin/bash

##-------------CopyRight-------------
# Name:sort string
# Version Number:1.1
# Type:sh
# Language:bash shell
# Date:--
# Author:sandy
# QQ:
# Email:eeexu123@.com str="the squid project provides a number of resources toassist users design,implement and support squid installations. Please browsethe documentation and support sections for more infomation"
#no1按单词出现的频率降序排序
word(){
echo $str|tr ' ' '\n'|sort|uniq -c|sort -rn -k1
} #no2按字母出现的频率降序排序
string(){
echo $str|sed -r 's#(.)#\1\n#g'|egrep -v "[^a-zA-Z]|^$"|sort|uniq -c|sort -rn -k1
} menu(){
cat <<END
.按单词出现的频率降序排序
.按字母出现的频率降序排序
END
read -p "Pls you choose num:" num
}
menu usage(){
echo "USAGE:You muset choose 1 or 2"
exit
} case "$num" in
)
word
;;
)
string
;;
*)
usage
esac

执行上述脚本,如果如下:

[root@mysql01 shell]# sh no_20.sh
1.按单词出现的频率降序排序
2.按字母出现的频率降序排序
Pls you choose num:1
2 support
2 squid
2 and
1 users
1 toassist
1 the
1 sections
1 resources
1 provides
1 project
1 Please
1 of
1 number
1 more
1 installations
1 infomation
1 implement
1 for
1 documentation
1 design
1 browsethe
1 a
[root@mysql01 shell]# sh no_20.sh
1.按单词出现的频率降序排序
2.按字母出现的频率降序排序
Pls you choose num:2
19 s
17 e
16 o
14 t
12 n
12 i
11 r
9 a
8 u
7 p
7 d
6 m
4 l
4 c
3 f
2 q
2 h
2 b
1 w
1 v
1 P
1 j
1 g

用shell处理以下内容 1、按单词出现频率降序排序! 2、按字母出现频率降序排序! the squid project provides a number of resources toassist users design,implement and support squid installations. Please browsethe documentation and support的更多相关文章

  1. shell脚本,按字母出现频率降序排序。

    [root@localhost oldboy]# cat file the squid project provides a number of resources toassist users de ...

  2. shell读取文件内容并进行变量赋值

    需求: shell读取文件内容,然后把内容赋值给变量然后进行字符串处理 实现: dataline=$(cat /root/data/data.txt) echo $dataline

  3. python3 获得shell的输出内容(subprocess.getstatusoutput)

    默认通过os.system(“shell")命令赋值,结果是0之类的,0表示shell命令运行正确 如果想获得shell输出的内容,可以通过[subprocess.getstatusoutp ...

  4. Java实验--统计字母出现频率及其单词个数

    本周的实验要求在之前实现统计单词的基础之上(可以见之前博客的统计单词的那个实验),对其进行修改成所需要的格式,统计字母出现频率的功能,并按照一定的格式把最终结果的用特定的格式在文本中显示出来 统计过程 ...

  5. [ SHELL编程 ] 文件内容大小写替换

    shell编程经常会碰到字符串.文件内容大小写的转换,在不同的场景下选择合适的命令可以提高编程效率. 适用场景 需大小写转换的文件内容或字符串 字符串大小写替换 小写替换大写 echo "h ...

  6. shell读取文件内容

           Shell脚本,执行解释速度快.代码简单易于理解.在shell代码编写过程中,经常会用到读取文件内容. 写法一: ------------------------------------ ...

  7. Shell 读取文本内容

    在Linux中有很多方法逐行读取一个文件的方法,其中最常用的就是下面的脚本里的方法,而且是效率最高,使用最多的方法.为了给大家一个直观的感受,我们将通过生成一个大的文件的方式来检验各种方法的执行效率. ...

  8. Shell读取文件内容【转】

    while read wOne wTwo wThreedo    [ -z $wOne ] && continue           #测试此行内容是否为空    xxx=$wOne ...

  9. Shell实现文件内容批量替换的方法

    在Linux系统中,文件内容的批量替换同Windows平台相比要麻烦一点.不过这里可以通过Shell命令或脚本的方式实现批量替换的功能. 笔者使用过两个命令:perl和sed ,接下来会对其做出说明. ...

随机推荐

  1. map.js的编写(js编写一个对象的方式)

    // 定义map function Map() { this.container = {}; } // 将key-value放入map中 Map.prototype.put = function(ke ...

  2. Linux 安装python爬虫框架 scrapy

    Linux 安装python爬虫框架 scrapy http://scrapy.org/ Scrapy是python最好用的一个爬虫框架.要求: python2.7.x. 1. Ubuntu14.04 ...

  3. Unity UGUI实现图文混排

    目前在unity实现图文混排的好像都是通过自定义字体然后在文本获取字符的位置,用图片替换掉图片标签,这样对于支持英文来说,并没有什么影响.然后对于中文来说就是一个相当麻烦的事了,毕竟图文混排多用于游戏 ...

  4. java中throw与throws

    类或函数声明,用throws表示,函数体中,可能抛出的错误,后接多个. 1.系统自动抛出的异常 系统定义的编译和运行异常都可以由系统自动抛出,称为标准异常. 2.语句抛出的异常 用户程序自定义的异常和 ...

  5. Dynamics CRM2011 通过DeveloperToolkit在VS中部署遇到的问题

    接上一篇继续,说个在部署的过程中我遇到了个问题:"Error registering plugins and/or workflows. Plug-in assembly does not ...

  6. iOS实现时间线列表效果(例如订单详情页面的效果)

    之前看到美团的订单详情页面很有特色,于是决定模仿一下这个效果. 其实就是简单的 TableView 技巧,下面我们就来一步一步实现它. 设计 TableViewCell 原型 子类化一个新的 UITa ...

  7. getJSONObject与optJSONObject的区别,结合源码分析

    *json解析常见问题: getJSONObject与optJSONObject的区别,下面结合源码和案例来分析当我们使用这两周方法来解析数据时,哪种比较好. 源码分析: //使用getJSONObj ...

  8. C语言生成32位和64位随机数算法

    C语言生成32位和64位随机数算法 /** * randstd.h * * Standard definitions and types, Bob Jenkins * * 2015-01-19: re ...

  9. Linux网络设置(第二版) --互联网寻址过程

    Linux网络设置 --互联网寻址过程 1.TCP/IP与OSI参考模型比较 TCP/IP OSI 物理层 网卡 数据链路层 * MAC地址 网络层 IP,ICMP,ARP协议 传输层 TCP,UDP ...

  10. 嵌入式C开发---用循环实现左移右移

    //将n左移m位 int byte_to_left_move(int n , int m) { int i , ret = 1 ; if(n == 0 || n < 0) { return ; ...