{ "data": { "question": { "questionId": "192", "questionFrontendId": "192", "categoryTitle": "Shell", "boundTopicId": 1312, "title": "Word Frequency", "titleSlug": "word-frequency", "content": "
Write a bash script to calculate the frequency of each word in a text file words.txt
.
For simplicity sake, you may assume:
\n\nwords.txt
contains only lowercase characters and space ' '
characters.Example:
\n\nAssume that words.txt
has the following content:
\nthe day is sunny the the\nthe sunny is is\n\n\n
Your script should output the following, sorted by descending frequency:
\n\n\nthe 4\nis 3\nsunny 2\nday 1\n\n\n
Note:
\n\n写一个 bash 脚本以统计一个文本文件 words.txt
中每个单词出现的频率。
为了简单起见,你可以假设:
\n\nwords.txt
只包括小写字母和 ' '
。示例:
\n\n假设 words.txt
内容如下:
the day is sunny the the\nthe sunny is is\n\n\n
你的脚本应当输出(以词频降序排列):
\n\nthe 4\nis 3\nsunny 2\nday 1\n\n\n
说明:
\n\n\\u7248\\u672c\\uff1aBash 4.3.30<\\/code><\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "a",
"__typename": "QuestionNode"
}
}
}