Word Frequency
2015-06-28 11:57
465 查看
Write a bash script to calculate the frequency of each word in a text file
For simplicity sake, you may assume:
Each word must consist of lowercase characters only.
Words are separated by one or more whitespace characters.
For example, assume that
Your script should output the following, sorted by descending frequency:
Write a bash script to calculate the frequency of each word in a text file
words.txt.
For simplicity sake, you may assume:
words.txtcontains only lowercase characters and space
' 'characters.
Each word must consist of lowercase characters only.
Words are separated by one or more whitespace characters.
For example, assume that
words.txthas 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,其中的数组是key-value形式
awk '{words[$1]+=1} END{for (word in words) {print word, words[word]}}' RS="[ \n]+" words.txt | sort -nrk2
相关文章推荐
- APUE 头文件apue.h 解决方法
- Java常见的queue(队列)类测试
- 【Arduino学习笔记】蓝牙控制手自两用避障车
- 在jfinal中使用druid,并配置查看权限
- LeetCode_60---Permutation Sequence
- 如果分配给命令的连接位于本地挂起事务中,ExecuteNonQuery 要求命令拥有事务。命令的 Transaction 属性尚未初始化
- [安卓]手机管家(二十一)杀毒UI及SlidingDrawer(抽屉效果)
- UIAlertView自动弹框创建步骤
- UI控件设置圆角
- UITextView弹簧效果属性
- 创建UIImageView方式的区别
- [iOS8][Segue转场]转场返回无法绑定的解决办法
- 【Leetcode】Combination Sum III #216
- Google interview question: quickSort-like questions
- Google interview question: mergeSort-like questions
- Arduino MPU6050学习资料总结
- 探究requestDisallowInterceptTouchEvent失效的原因
- iOS开发——CoreBluetooth蓝牙开发(三)
- c#中使用easyUI的DataGrid组件
- 重装操作系统后,要重新配置Android开发环境。配置成功后,添加原本项目时却出现了错误! Android requires compiler compliance level 5.0 or 6.0.