{ "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.

\n\n

For simplicity sake, you may assume:

\n\n\n\n

Example:

\n\n

Assume that words.txt has the following content:

\n\n
\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\n", "translatedTitle": "统计词频", "translatedContent": "

写一个 bash 脚本以统计一个文本文件 words.txt 中每个单词出现的频率。

\n\n

为了简单起见,你可以假设:

\n\n\n\n

示例:

\n\n

假设 words.txt 内容如下:

\n\n
the day is sunny the the\nthe sunny is is\n
\n\n

你的脚本应当输出(以词频降序排列):

\n\n
the 4\nis 3\nsunny 2\nday 1\n
\n\n

说明:

\n\n\n", "isPaidOnly": false, "difficulty": "Medium", "likes": 224, "dislikes": 0, "isLiked": null, "similarQuestions": "[{\"title\": \"Top K Frequent Elements\", \"titleSlug\": \"top-k-frequent-elements\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u524d K \\u4e2a\\u9ad8\\u9891\\u5143\\u7d20\", \"isPaidOnly\": false}]", "contributors": [], "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", "topicTags": [ { "name": "Shell", "slug": "shell", "translatedName": null, "__typename": "TopicTagNode" } ], "companyTagStats": null, "codeSnippets": [ { "lang": "Bash", "langSlug": "bash", "code": "# Read from the file words.txt and output the word frequency list to stdout.", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"32.9K\", \"totalSubmission\": \"92.7K\", \"totalAcceptedRaw\": 32862, \"totalSubmissionRaw\": 92678, \"acRate\": \"35.5%\"}", "hints": [], "solution": null, "status": null, "sampleTestCase": "a", "metaData": "{\n \"shell\": true,\n \"manual\": true\n}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [], "enableRunCode": false, "envInfo": "{\"bash\":[\"Bash\",\"

\\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" } } }