Write a bash script to calculate the frequency of each word in a text file words.txt.

For simplicity sake, you may assume:

  • words.txt contains only lowercase characters and space ' ' characters.
  • Each word must consist of lowercase characters only.
  • Words are separated by one or more whitespace characters.

Example:

Assume that words.txt has the following content:

the day is sunny the the
the sunny is is

Your script should output the following, sorted by descending frequency:

the 4
is 3
sunny 2
day 1 统计单词出现的次数,并倒序输出
awk '{for(i=1;i<=NF;i++)res[$i]++}END{for(var in res)print var , res[var] | "sort -k 2 -nr"}' words.txt
 

192 Word Frequency的更多相关文章

  1. LeetCode(192. Word Frequency)

    192. Word Frequency Write a bash script to calculate the frequency of each word in a text file words ...

  2. LeetCode 192. Word Frequency

    分析 写bash,不太会啊…… 难度 中 来源 https://leetcode.com/problems/word-frequency/ 题目 Write a bash script to calc ...

  3. [leetcode shell]192. Word Frequency

    统计words.txt中每个单词出现的次数并排序 解法1: cat words.txt | tr -s ' ' '\n' | sort | uniq -c | sort -r | awk '{prin ...

  4. Individual Project - Word frequency program-11061171-MaoYu

    BUAA Advanced Software Engineering Project:  Individual Project - Word frequency program Ryan Mao (毛 ...

  5. Word Frequency

    https://leetcode.com/problems/word-frequency/ Write a bash script to calculate the frequency of each ...

  6. [Bash]LeetCode192. 统计词频 | Word Frequency

    Write a bash script to calculate the frequency of each word in a text file words.txt. For simplicity ...

  7. [LeetCode] Word Frequency 单词频率

    Write a bash script to calculate the frequency of each word in a text file words.txt. For simplicity ...

  8. [CareerCup] 17.9 Word Frequency in a Book 书中单词频率

    17.9 Design a method to find the frequency of occurrences of any given word in a book. 这道题让我们找书中单词出现 ...

  9. Individual Project - Word frequency program - Multi Thread And Optimization

    作业说明详见:http://www.cnblogs.com/jiel/p/3978727.html 一.开始写代码前的规划: 1.尝试用C#来写,之前没有学过C#,所以打算先花1天的时间学习C# 2. ...

随机推荐

  1. Eclipse Groovy插件使用时出现的错误 org.eclipse.core.runtime.InvalidRegistryObjectException: Invalid registry object

    在eclipse marketplace中下载了groovy插件,发现使用的groovy版本跟项目中使用的groovy版本不一致. 于是在Preferences -> Groovy -> ...

  2. .Net进阶系列(12)-异步多线程(Thread和ThreadPool)(被替换)

    一. Thread多线程   1. 两种使用方式 通过F12查看Thread后,发现有两类构造函数,ParameterizedThreadStart和ThreadStart,其中 ThreadStar ...

  3. 简易selenium自动化测试框架(Python)

    最近空闲时间在探索Selenium的自动化测试,简单的写了一个小框架来测试公司的一个web产品.该框架包括以下模块: 1. Test case编写模式(page模式,参考之前的博文http://www ...

  4. intellj(idea) 编译项目时在warnings 页签框里 报 “xxx包不存在” 或 “找不到符号” 或 “未结束的字符串字面值” 或 “需要)” 或 “需要;”等错误提示

    如上图: 环境 是 刚换的系统,重装的Intellj,直接双击老的皇帝项目中的idea的 .iml文件,结果 打开 intellj 后,进行 ctrl +shift +F9 编译时 尽然报 错误提示, ...

  5. MySQL - 日常操作三 mysql慢查询;

    sql语句使用变量 use testsql; set @a=concat('my',weekday(curdate())); # 组合时间变量 set @sql := concat('CREATE T ...

  6. Mac下压力测试工具siege

    安装: brew install siege 用法: siege -c 并发数 -t 运行测试时间 URL 如: siege -c 1000 -t 5S URL 这里要注意的是-t后面的时间要带单位, ...

  7. (原创)高仿360云盘android端的UI实现

    前些日子几大互联网巨头展开了一轮网盘空间大战.一下子从G级别提高到了T级别.以后谁的空间没有1T估计都不好意思开口了~~~ 试用了一下360云盘的客户端,比较小清新(不是给360打广告~~~).刚好U ...

  8. mysql 原理~ index的详解

    一 简介:今天咱们来介绍下index的一些东西 二 数据的基本存储结构 1 磁盘空间被划分为许多大小相同的块(Block) 在内存中读出是页(Page).   2 一个表的这些数据块以链表的方式串联在 ...

  9. Database学习 - mysql 数据库 事务操作

    事务 事务指逻辑上的一组操作,组成这组操作的各个单元,要不全部成功,要不全部不成功. 数据库开启事务命令: start transaction   开启事务 rollback  回滚事务,即撤销指定的 ...

  10. oracle里的tns是什么意思

    参考http://www.jb51.net/article/44668.htm TNS简要介绍与应用 Oracle中TNS的完整定义:transparence Network Substrate透明网 ...