统计words.txt中每个单词出现的次数并排序

解法1:

cat words.txt | tr -s ' ' '\n' | sort | uniq -c | sort -r | awk '{print $2,$1}'

解法2:

cat words.txt | awk '{for(i=1;i<=NF;i++){count[$i]++}}END{for (i in count){print i,count[i]}}' | sort -k2nr

[leetcode shell]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. 192 Word Frequency

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

  4. LeetCode Shell Problems

    195. Tenth Line -- 第十行 How would you print just the 10th line of a file? Solution: awk 'NR==10' file ...

  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. Individual Project - Word frequency program-11061171-MaoYu

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

  8. leetcode面试准备: Word Pattern

    leetcode面试准备: Word Pattern 1 题目 Given a pattern and a string str, find if str follows the same patte ...

  9. [leetcode]244. Shortest Word Distance II最短单词距离(允许连环call)

    Design a class which receives a list of words in the constructor, and implements a method that takes ...

随机推荐

  1. HDU 2073 叠框

    解题报告:一个字符串的题,最恶心的还是格式问题,PE了很多次,要求是每个测试数据的后面都带有一个空行,但是最后一个不能有空行,所以只能把第一组 数据的前面不输出空行,而后面的每一组数据都输出空行,这样 ...

  2. seq与Shell序列生成

    有时候可能有这样的需要:用Shell生成类似0001这样的序列作为批次号,这里整理了一下个人的方法 方法一:通过seq命令 seq命令可以生成从某个数字到递增到另一数字的序列.用法如下: # seq ...

  3. [NOI2007]货币兑换 「CDQ分治实现斜率优化」

    首先每次买卖一定是在某天 $k$ 以当时的最大收入买入,再到第 $i$ 天卖出,那么易得方程: $$f_i = \max \{\frac{A_iRate_kf_k}{A_kRate_k + B_k} ...

  4. Django中cookie和session

    cookie Cookie的由来 大家都知道HTTP协议是无状态的. 无状态的意思是每次请求都是独立的,它的执行情况和结果与前面的请求和之后的请求都无直接关系,它不会受前面的请求响应情况直接影响,也不 ...

  5. JAVA中分为基本数据类型和引用数据类型区别

    一.基本数据类型: byte:Java中最小的数据类型,在内存中占8位(bit),即1个字节,取值范围-128~127,默认值0 short:短整型,在内存中占16位,即2个字节,取值范围-32768 ...

  6. SQL-如果指定值存在返回1,如果不存在返回0的SQL语句

    想实现简单的判断一个表中是否有一条记录,可以用这个方式.如以下,table_name是表名,column1是列名. 这条语句会在此条记录存在的时候返回1,不存在时返回0. FROM table_nam ...

  7. Python_oldboy_自动化运维之路_全栈考试(七)

    1. 计算100-300之间所有能被3和7整除的所有数之和 # -*- coding: UTF-8 -*- #blog:http://www.cnblogs.com/linux-chenyang/ c ...

  8. thinkphp模型实例化

    方法一 方法二

  9. Java标记接口

    写在前面的话:读书破万卷,编码如有神--------------------------------------------------------------------这篇博客主要来谈谈" ...

  10. CF475C. Kamal-ol-molk's Painting

    C. Kamal-ol-molk's Painting time limit per test 2 seconds memory limit per test 256 megabytes input ...