加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

将一段(英文)按照字符出现的频率进行倒序排列

发布时间:2020-12-14 04:16:30 所属栏目:大数据 来源:网络整理
导读:1、文章 Newly-added concrete barriers and steel posts can be seen alongside the bike path,and more will be installed in the coming months across the city,as the NYPD has promised. 2、操作过程: 2.1 将文中的换行符替换成空格 tr ‘n‘ ‘ ‘
1、文章

Newly-added concrete barriers and steel posts can be seen alongside
the bike path,and more will be installed in the coming months across the city,as the NYPD has promised.

2、操作过程:

2.1 将文中的换行符替换成空格
tr ‘n‘ ‘ ‘ <a.txt
2.2 将空格去除
sed ‘s# ##g‘
2.3 将单词拆分成单个字母并换行
grep -o ‘w‘
2.4 单词出现的频率进行倒序
sort|uniq -c|sort -rn

3、最后的执行语句为:(此语句是将区分大小写的)
tr ‘n‘ ‘ ‘ <a.txt|sed ‘s# ##g‘|grep -o ‘w‘ |sort|uniq -c |sort -rn

20 e
13 s
11 t
11 a
10 n
9 i
8 o
8 d
7 r
7 l
7 h
6 c
4 m
4 b
3 p
2 y
2 w
2 N
2 g
1 Y
1 P
1 k
1 D

4、tr ‘n‘ ‘ ‘ <a.txt|awk ‘{print toupper($0)}‘|sed ‘s# ##g‘|grep -o ‘w‘ |sort|uniq -c |sort -rn

20 e
 13 s
 12 n
 11 t
 11 a
  9 i
  9 d
  8 o
  7 r
  7 l
  7 h
  6 c
  4 p
  4 m
  4 b
  3 y
  2 w
  2 g
  1 k

5、大小写转换:

awk ‘{print toupper($0)}‘ <a.txt (转化为大写)awk ‘{print tolower($0)}‘ <a.txt (转化为小写)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读