2 Star 10 Fork 2

CG国斌 / myleetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
_192.sh 932 Bytes
一键复制 编辑 原始数据 按行查看 历史
Charies Gavin 提交于 2020-02-06 12:44 . 初始化 myleetcode 项目
#!/usr/bin/env bash
## 192. Word 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.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
## Note:
##
## Don't worry about handling ties, it is guaranteed that each word's frequency count is unique.
## Could you write it in one-line using Unix pipes?
##
## Read from the file words.txt and output the word frequency list to stdout.
cat words.txt | tr -s ' ' '\n' | sort | uniq -c | sort -r | awk '{ print $2, $1 }'
Java
1
https://gitee.com/guobinhit/myleetcode.git
git@gitee.com:guobinhit/myleetcode.git
guobinhit
myleetcode
myleetcode
master

搜索帮助