转(linux shell)(2)
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
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
[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
1
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
1
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
1
v
1 j
1 g
1 P
1 .
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
1
v
1 j
1 g
1 P
1 .
1 ,
转(linux shell)(2)的更多相关文章
- linux shell 中的sleep命令
开始还以为是这样的语法: sleep(1), 后面发现是: linux shell 中的sleep命令 分类: LINUX 在有的shell(比如linux中的bash)中sleep还支持睡眠(分,小 ...
- Linux shell脚本编程(三)
Linux shell脚本编程 流程控制: 循环语句:for,while,until while循环: while CONDITION; do 循环体 done 进入条件:当CONDITION为“真” ...
- Linux shell脚本编程(二)
Linux shell脚本编程(二) 练习:求100以内所有偶数之和; 使用至少三种方法实现; 示例1: #!/bin/bash # declare -i sum=0 #声明一个变量求和,初始值为0 ...
- Linux shell脚本编程(一)
Linux shell脚本编程: 守护进程,服务进程:启动?开机时自动启动: 交互式进程:shell应用程序 广义:GUI,CLI GUI: CLI: 词法分析:命令,选项,参数 内建命令: 外部命令 ...
- Linux Shell 流程控制语句
* 本文主要介绍一些Linux Shell 常用的流程控制语句* 1. if 条件语句:if-then/if-elif-fi/if- else-fi if [条件判断逻辑1];then command ...
- Linux Shell 截取字符串
Linux Shell 截取字符串 shell中截取字符串的方法很多 ${var#*/} ${var##*/} ${var%/*} ${var%%/*} ${var:start:len} ${var: ...
- Linux Shell 重定向与管道【转帖】
by 程默 在了解重定向之前,我们先来看看linux 的文件描述符. linux文件描述符:可以理解为linux跟踪打开文件,而分配的一个数字,这个数字有点类似c语言操作文件时候的句柄,通过句柄就可以 ...
- Linux Shell 通配符、元字符、转义符【转帖】
作者:程默 说到shell通配符(wildcard),大家在使用时候会经常用到.下面是一个实例: 1 1 2 3 4 [chengmo@localhost ~/shell]$ ls a.txt ...
- Linux Shell中单引号、双引号、反引号的区别【转载】
linux shell可以识别4种不同类型的引字符号: 单引号字符' 双引号字符" 反斜杠字符\ 反引号字符` 1. 单引号 ( '' )# grep Susan phonebook Sus ...
- 【shell 大系】Linux Shell常用技巧
在最近的日常工作中由于经常会和Linux服务器打交道,如Oracle性能优化.我们数据采集服务器的资源利用率监控,以及Debug服务器代码并解决其效率和稳定性等问题.因此这段时间总结的有关Linux ...
随机推荐
- HDU 3966 (树链剖分+线段树)
Problem Aragorn's Story (HDU 3966) 题目大意 给定一颗树,有点权. 要求支持两种操作,将一条路径上的所有点权值增加或减少ai,询问某点的权值. 解题分析 树链剖分模板 ...
- Extjs学习笔记(-):ComboBox联动
http://www.cnblogs.com/wumin97136/archive/2007/12/24/1012720.html http://examples.ext.net/ http://ex ...
- 表视图控制器(TableViewController)(一)
1 创建一个UITableViewController并展示简单数据 1.1 问题 有很多移动客户端的应用都是采用表的形式来展示数据,因为表视图能使数据看起来更规整.更有调理,比如微信界面就是使用的表 ...
- lstm的debug模式下编译不行貌似
待验证,因为也可能是 USE_CUDNN := 1被注释掉的原因
- CART
一.为什么有CART回归树 以前学过全局回归,顾名思义,就是指全部数据符合某种曲线.比如线性回归,多项式拟合(泰勒)等等.可是这些数学规律多强,硬硬地将全部数据逼近一些特殊的曲线.生活中的数据可是千变 ...
- Struts2 中遇到的问题
1. 警告: Could not find action or result: /Struts2Test/register.actionThere is no Action mapped for na ...
- 1024PHP数组
<?php //定义数组//$attr = array();//$attr[0] = 1;//索引数组//$attr = array(1,2,3,4);//关联数组//$attr = array ...
- postgresql 分区表创建及测试
1 建立分区 1.1. 创建主表 CREATE TABLE measurement ( city_id int not null, logdate date ...
- jquery 平滑滚动页面到某个锚点
$(document).ready(function() { $("a.topLink").click(function() { $ ...
- Delphi第一个入门程序——鼠标点击计数 - imsoft.cnblogs
实现的效果如下: 制作要点: 添加一个按钮Button1和一个标签Label1,并双击按钮进入编程界面在var Form1: TForm1;下面一行加上 n:integer;//定义变量. 然后在 ...