{ "data": { "question": { "questionId": "192", "questionFrontendId": "192", "boundTopicId": null, "title": "Word Frequency", "titleSlug": "word-frequency", "content": "<p>Write a bash script to calculate the frequency of each word in a text file <code>words.txt</code>.</p>\r\n\r\n<p>For simplicity sake, you may assume:</p>\r\n\r\n<ul>\r\n\t<li><code>words.txt</code> contains only lowercase characters and space <code>' '</code> characters.</li>\r\n\t<li>Each word must consist of lowercase characters only.</li>\r\n\t<li>Words are separated by one or more whitespace characters.</li>\r\n</ul>\r\n\r\n<p><strong>Example:</strong></p>\r\n\r\n<p>Assume that <code>words.txt</code> has the following content:</p>\r\n\r\n<pre>\r\nthe day is sunny the the\r\nthe sunny is is\r\n</pre>\r\n\r\n<p>Your script should output the following, sorted by descending frequency:</p>\r\n\r\n<pre>\r\nthe 4\r\nis 3\r\nsunny 2\r\nday 1\r\n</pre>\r\n\r\n<p><b>Note:</b></p>\r\n\r\n<ul>\r\n\t<li>Don't worry about handling ties, it is guaranteed that each word's frequency count is unique.</li>\r\n\t<li>Could you write it in one-line using <a href=\"http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-4.html\">Unix pipes</a>?</li>\r\n</ul>\r\n", "translatedTitle": null, "translatedContent": null, "isPaidOnly": false, "difficulty": "Medium", "likes": 349, "dislikes": 234, "isLiked": null, "similarQuestions": "[{\"title\": \"Top K Frequent Elements\", \"titleSlug\": \"top-k-frequent-elements\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]", "exampleTestcases": "a", "categoryTitle": "Shell", "contributors": [], "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.\n", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"36.5K\", \"totalSubmission\": \"142.5K\", \"totalAcceptedRaw\": 36457, \"totalSubmissionRaw\": 142476, \"acRate\": \"25.6%\"}", "hints": [], "solution": null, "status": null, "sampleTestCase": "a", "metaData": "{\n \"shell\": true,\n \"manual\": true\n}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [], "enableRunCode": false, "enableTestMode": false, "enableDebugger": false, "envInfo": "{\"bash\": [\"Bash\", \"<p><code>Bash 4.3.30</code>.</p>\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }