Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions problems/word-frequency/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<!--|@home https://github.com/openset/leetcode |-->
<!--+----------------------------------------------------------------------+-->

[< Previous](https://github.com/openset/leetcode/tree/master/problems/number-of-1-bits "Number of 1 Bits")

[Next >](https://github.com/openset/leetcode/tree/master/problems/valid-phone-numbers "Valid Phone Numbers")

## 192. Word Frequency (Medium)

<p>Write a bash script to calculate the frequency of each word in a text file <code>words.txt</code>.</p>
Expand Down
5 changes: 5 additions & 0 deletions problems/word-frequency/word_frequency.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

# Read from the file words.txt and output the word frequency list to stdout.

awk '{for(i=1;i<=NF;i++) a[$i]++} END {for(k in a) print k,a[k]}' words.txt | sort -k2 -nr
2 changes: 2 additions & 0 deletions problems/word-frequency/words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
the day is sunny the the
the sunny is is