转(linux shell)(2)
2024-10-14 14:21:56
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
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 ,
最新文章
- 关于ie11 的开发者工具
- 在 Django 模板中遍历复杂数据结构的关键是句点字符
- android.support.v4包中的LruCache源码简读
- mootools里选择器$,$$,$E,$ES等的区别
- android shape(如自定义Button)
- freeCodeCamp:Sorted Union
- [转] Linux strace 简介
- 安卓开发之viewpager学习(头条显示)
- IDL 遍历 XML文档示例
- webstorm 编辑器破解 (麻麻再也不用担心过期了)
- mybatis源码学习--spring+mybatis注解方式为什么mybatis的dao接口不需要实现类
- HI3531的DDR3配置流程
- PHP-循环结构-数组(难)
- .net core开发工具与SDK
- Java的第一个晞月自己打的程序
- Codeforces 787D. Legacy 线段树建模+最短路
- spring @component的作用
- Ansible Tower系列 三(使用tower执行一个任务)【转】
- Zookeeper Tutorial 1 -- Overview
- 牛客多校第四场 J.Hash Function(线段树优化建图+拓扑排序)
热门文章
- 重学STM32---(十) ——CAN通信(二)
- php <;? ?>; <;?php ?>;
- hadoop shell 详解
- Apache CXF 101 Win Eclipse开发环境搭建
- 使用Jsoup函数包抓取网页内容
- jq中的三元运算结构
- oracle锁机制
- leetcode 114 Flatten Binary Tree to Linked List ----- java
- 第n小的质数
- Codeforces378 D Kostya the Sculptor(贪心)(逻辑)