排序的字符串如下: 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. Leetcode_172_Factorial Trailing Zeroes

    本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/42417535 Given an integer n, re ...

  2. linux知识汇总

    1.     利用Ctrl+Alt+F1到Ctrl+Alt+F6在6个虚拟控制台之间切换,利用Ctrl+Alt+F7切换回图形界面. 2.     使用who命令来判断谁在系统上及其登录方式.id命令 ...

  3. 09_EGIT插件的安装,Eclipse中克隆(clone),commit,push,pull操作演示

     1 下载EGIT,下载地址:http://www.eclipse.org/egit/download/ 最终的下载地址: http://www.eclipse.org/downloads/dow ...

  4. RB-tree (红黑树)相关问题

    今天被问到了红黑树的规则,简述总结一下: 1.每个节点不是红色就是黑色. 2.根节点为黑色. 3.如果节点为红,其子节点必须为黑. 4.任一节点至NULL(树尾端)的任何路径,所含之黑节点数必须相同. ...

  5. windows linux—unix 跨平台通信集成控制系统

    首先,我们可以用到这个开源的开发包: mdk(Micro-Development-Kit)微量级软件开发包,提供几个常用类,主要实现了一个高性能的并发服务器引擎 使用c++开发,是一个跨平台的开发包, ...

  6. ERP-非财务人员的财务培训教(三)------公司/部门预算编制与评价

    一.预算管理中的行为问题 二.编制预算中的问题 三.经营计划与预算制度                第一节 经营目标      第二节 预算编制的内容及说明      第三节 推行预算制度的组织 第 ...

  7. 初探linux子系统集之写在前言

    毕业两周年,进入嵌入式linux这个行业也已两个年头有余,从开始的linux驱动,android的framework,到现在的linux应用,android的app以及产品的零零总总,其实很想把这些都 ...

  8. SharePoint2010搜索的简单设置

    1.  开启搜索服务,管理中心 – 应用程序管理 – 服务应用程序 – 管理服务器上的服务 2.  点击进去,启动"SharePoint Foundation搜索"."S ...

  9. ruby中顶层定义的方法究竟放在哪里?

    ruby中顶层(top level)中定义的方法放在main中,证明如下: self.private_methods(false) #IN TOP LEVEL 那么methods方法究竟是在哪定义的, ...

  10. Nginx安装Nginx-echo模块

    Nginx-echo可以在Nginx中用来输出一些信息,是在测试排错过程中一个比较好的工具.它也可以做到把来自不同链接地址的信息进行一个汇总输出.总之能用起来可以给开发人员带来挺大帮助的.下面看看我们 ...