Created
June 3, 2017 23:31
-
-
Save BiruLyu/7bed471c5f3b37450a97d5cdc15d4414 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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}' | |
| #tr -s: truncate the string with target string, but only remaining one instance (e.g. multiple whitespaces) | |
| #sort: To make the same string successive so that uniq could count the same string fully and correctly. | |
| #uniq -c: uniq is used to filter out the repeated lines which are successive, -c means counting | |
| #sort -r: -r means sorting in descending order | |
| #awk '{ print $2, $1 }': To format the output, see https://linux.cn/article-3945-1.html. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment