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. bootstrap3 input 验证样式【转】

    feedback <form role="form"> <div class="form-group has-success has-feedback& ...

  2. git commit 时出现:please enter the commit message for your changes

    每次准备提交前,先用 git status 看下,是不是都已暂存起来了,然后再运行提交命令 git commit: $ git commit 这种方式会启动文本编辑器以便输入本次提交的说明.(默认会启 ...

  3. JavaScript 数字转汉字+element时间选择器快速选择

    window.CN = { : '一', : '二', : '三', : '四', : '五', : '六', : '七', : '八', : '九', : '零' } window.LEVEL = ...

  4. 后台拿webshell方法(2)

    在这里总结一下后台拿webshell的方法: 备份突破(在博客上有随笔介绍) 一般在后台上传文件类型受到限制,可以利用数据库备份将其上传的格式改为后门执行格式即可: asp更改为jpg     jpg ...

  5. luogu P4778 Counting swaps

    计数套路题?但是我连套路都不会,,, 拿到这道题我一脸蒙彼,,,感谢@poorpool 大佬的博客的指点 先将第\(i\)位上的数字\(p_i\)向\(i\)连无向边,然后构成了一个有若干环组成的无向 ...

  6. 【加密】Md5Util

    import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Md5U ...

  7. jQuery - ajaxUpLoad.js

    ajaxFileUpload是一个异步上传文件的jQuery插件 语法:$.ajaxFileUpload([options]) options参数说明: 参数 作用 url 上传处理程序地址 file ...

  8. A - 地精部落 (DP)

    题目链接:https://cn.vjudge.net/contest/281960#problem/A 题目大意:中文题目. 具体思路:首先,如果有一段是山谷的话,那么这一段中也能用来表示山峰,只要将 ...

  9. JavaScript中Function的拓展

    Function 是什么东西,就是JavaScript中的顶级类,系统级别的类.我们平时写的函数方法例如下. function Animal() { } Animal就是Function的实例,但是在 ...

  10. 【转】Python中的运算符

    [转]Python中的运算符 说完常用的数据类型,再来说下运算符.运算符用于将各种类型的数据进行运算,让静态的数据跑起来. 编程语言中的运算大致分为以下几个大类: 算术运算, 用于加减乘除等数学运算 ...