http://oldboy.blog.51cto.com/2561410/1665163
1、按单词出现频率降序排序!
2、按字母出现频率降序排序!
the squid project provides a number of resources to assist users design,implement and support squid installations. Please browse the documentation and support sections for more infomation
 
解答:
cat test.txt 
the squid project provides a number of resources to assist users design,implement and support squid installations. Please browse the documentation and support sections for more infomation
 
按单词排序解答:
法1:
[root@oldboy ~]# awk -F "[,. ]" '{for(i=1;i<=NF;i++)array[$i]++}END{for(key in array)print array[key],key|"sort -nr"}' oldboy.txt|column -t
2  the
2  support
2  squid
2  and
1  users
1  to
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  browse
1  assist
1  a
1
法2:
[root@MySQL ~]# tr "[ ,.]" "\n"<oldboy.txt|grep -v "^$"|sort|uniq -c|sort -rn 
      2 the
      2 support
      2 squid
      2 and
      users
      1 to
      1 sections
      1 resources
      1 provides
      1 project
      1 Please
      1 of
      1 number
      more
      1 installations
      1 infomation
      1 implement
      for
      1 documentation
      1 design
      1 browse
      1 assist
      1 a
 
按字母频率排序
法1
[root@MySQL ~]# tr "{ |,|.}" "\n"<oldboy.txt|awk -F ""  '{for(i=1;i<=NF;i++)array[$i]++}END{for(key in array)print array[key],key|"sort -nr"}'
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
v
1 P
1 j
1 g
 
[root@MySQL ~]# tr "[ ,.]" "\n"<oldboy.txt|awk '{for(i=1; i<=length($0); i++) ++S[substr($0,i,1)]} END {for(a in S) print S[a], a|"sort -rn"}'
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
v
1 P
1 j
1 g
 
 
[root@db02 oldboy20151227]# echo "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"|sed 's# ##g'|sed -r 's#(.)#\1\n#g'|sort|uniq -c|sort -rn -k1
     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
      v
      1 j
      1 g
      1 P
      1 .
      1 ,
      
       
      [root@db02 oldboy20151227]# echo "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"|sed 's# ##g'|awk -F "" '{for(n=1;n<=NF;n++) print $n}'|sort|uniq -c|sort -k1 -nr
     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
      v
      1 j
      1 g
      1 P
      1 .
      1 ,

转(linux shell)(2)的更多相关文章

  1. linux shell 中的sleep命令

    开始还以为是这样的语法: sleep(1), 后面发现是: linux shell 中的sleep命令 分类: LINUX 在有的shell(比如linux中的bash)中sleep还支持睡眠(分,小 ...

  2. Linux shell脚本编程(三)

    Linux shell脚本编程 流程控制: 循环语句:for,while,until while循环: while CONDITION; do 循环体 done 进入条件:当CONDITION为“真” ...

  3. Linux shell脚本编程(二)

    Linux shell脚本编程(二) 练习:求100以内所有偶数之和; 使用至少三种方法实现; 示例1: #!/bin/bash # declare -i sum=0 #声明一个变量求和,初始值为0 ...

  4. Linux shell脚本编程(一)

    Linux shell脚本编程: 守护进程,服务进程:启动?开机时自动启动: 交互式进程:shell应用程序 广义:GUI,CLI GUI: CLI: 词法分析:命令,选项,参数 内建命令: 外部命令 ...

  5. Linux Shell 流程控制语句

    * 本文主要介绍一些Linux Shell 常用的流程控制语句* 1. if 条件语句:if-then/if-elif-fi/if- else-fi if [条件判断逻辑1];then command ...

  6. Linux Shell 截取字符串

    Linux Shell 截取字符串 shell中截取字符串的方法很多 ${var#*/} ${var##*/} ${var%/*} ${var%%/*} ${var:start:len} ${var: ...

  7. Linux Shell 重定向与管道【转帖】

    by 程默 在了解重定向之前,我们先来看看linux 的文件描述符. linux文件描述符:可以理解为linux跟踪打开文件,而分配的一个数字,这个数字有点类似c语言操作文件时候的句柄,通过句柄就可以 ...

  8. Linux Shell 通配符、元字符、转义符【转帖】

    作者:程默 说到shell通配符(wildcard),大家在使用时候会经常用到.下面是一个实例: 1   1 2 3 4 [chengmo@localhost ~/shell]$ ls a.txt  ...

  9. Linux Shell中单引号、双引号、反引号的区别【转载】

    linux shell可以识别4种不同类型的引字符号: 单引号字符' 双引号字符" 反斜杠字符\ 反引号字符` 1. 单引号 ( '' )# grep Susan phonebook Sus ...

  10. 【shell 大系】Linux Shell常用技巧

    在最近的日常工作中由于经常会和Linux服务器打交道,如Oracle性能优化.我们数据采集服务器的资源利用率监控,以及Debug服务器代码并解决其效率和稳定性等问题.因此这段时间总结的有关Linux ...

随机推荐

  1. Debian 入门安装与配置2

    Debian 入门安装与配置2 1. C/C++开发必装软件 atp-get install gcc    这个不用说,用来编译C程序 apt-get install g++ 用来编译C++程序 ap ...

  2. RelativeLayout相对布局

    RelativeLayout相对布局常用属性: 第一类:属性值为true或false android:layout_centerHrizontal 水平居中 android:layout_center ...

  3. MyEclipse+Struts+Hibernate+Mysql开发环境配置

    软件: jdk-6u22-windows-x64.exe apache-tomcat-6.0.29.exe mysql-5.1.51-winx64.exe myeclipse-8.6.0-win32. ...

  4. easyui 入门

    http://www.cnblogs.com/tangge/p/3214496.html 1.页面引用. jquery,easyui,主题easyui.css,图标ico.css,语言zh_CN.js ...

  5. 快排算法(C++版)

    #include <iostream> using namespace std; /** Quick Sort * * split: cmp && swap * left ...

  6. 快速对字符转义,避免跨站攻击XSS

    XSS已经成为非常流行的网站攻击方式,为了安全起见,尽量避免用户的输入.可是有些情况下不仅不避免,反而要求鼓励输入,比如写博客.博客园开放性很高,可以运行手写的JS.之前比较著名的例子就是,凡是看到某 ...

  7. 350. Intersection of Two Arrays II

    Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1] ...

  8. Angular 通过 $http.post 写入本地 JSON 文件

    最近在练习使用 Angular,在实现 $http 对本地 JSON 文档读写的时候遇到了问题. 问题 使用 GET 方法成功将 JSON 文档的内容读出来:但是在使用 POST 插入本地 JSON ...

  9. Javascript中的函数、this以及原型

    关于函数 在Javascript中函数实际上就是一个对象,具有引用类型的特征,所以你可以将函数直接传递给变量,这个变量将表示指向函数“对象"的指针,例如: function test(mes ...

  10. Validform:一行代码搞定整站的表单验证!

    表单验证不再发愁,http://validform.rjboy.cn/