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. Dapper总结(一)---基本CRUD操作

    一.dapper是什么 dapper是一款轻量级的ORM(Object Relationship Mapper),它负责数据库和编程语言之间的映射.SqlConnection,MysqlConnect ...

  2. Java编程思想 学习笔记5

    五.初始化与清理 1.用构造器确保初始化  在Java中,通过提供构造器,类的设计者可确保每个对象都会得到初始化.创建对象时,如果其类具有构造器,Java就会在用户有能力操作对象之前自动调用相应的构造 ...

  3. 嵌入式iframe子页面与父页面js通信方式

    iframe框架中的页面与主页面之间的通信方式根据iframe中src属性是同域链接还是跨域链接,有明显不同的通信方式,同域下的数据交换和DOM元素互访就简单的多了,而跨域的则需要一些巧妙的方式来实现 ...

  4. oracle sum(x) over( partition by y ORDER BY z ) 分析

    之前用过row_number(),rank()等排序与over( partition by ... ORDER BY ...),这两个比较好理解: 先分组,然后在组内排名. 今天突然碰到sum(... ...

  5. .net 读写xml

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  6. 第5月第6天 NSOperation isConcurrent category同名覆盖

    1. @implementation AFURLConnectionOperation ... - (BOOL)isConcurrent { return YES; } NSOperation调用st ...

  7. [CERC2016]机棚障碍 Hangar Hurdles(kruskal重构树+树上倍增)

    题面 \(solution:\) 某蒟蒻的心路历程: 这一题第一眼感觉很奇怪 带障碍物的图,最大的集装箱? 首先想到的就是限制我集装箱大小条件的是什么: 如果我要在某一个点上放一个集装箱且使它最大, ...

  8. 为小程序开发创建本地mock数据服务器

    开发时使用easy-mock的服务,不是大厂就不是大厂,实在恶心,每天都会有卡的这么一段时间 于是,自己建个本地mock服务算了,想使用express 但是必须把json数据里面的不同对象,分配到不同 ...

  9. jenkins配置sonarqube

    jenkins配置sonarqube 下载插件SonarQube Scanner for Jenkins 在系统管理系统设置中选择 SonarQube servers 配置服务器名称.访问URL地址, ...

  10. Python sys.path详细介绍

    如何将路径“永久"添加到sys.path? sys.path是python的搜索模块的路径集,是一个list 复制代码 代码如下: ['', 'C:\\WINDOWS\\system32\\ ...