diff --git a/problems/word-frequency/README.md b/problems/word-frequency/README.md index cb096378b..97be1df34 100644 --- a/problems/word-frequency/README.md +++ b/problems/word-frequency/README.md @@ -5,6 +5,10 @@ +[< 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)

Write a bash script to calculate the frequency of each word in a text file words.txt.

diff --git a/problems/word-frequency/word_frequency.bash b/problems/word-frequency/word_frequency.bash new file mode 100755 index 000000000..fe817eebd --- /dev/null +++ b/problems/word-frequency/word_frequency.bash @@ -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 diff --git a/problems/word-frequency/words.txt b/problems/word-frequency/words.txt new file mode 100644 index 000000000..18d52475f --- /dev/null +++ b/problems/word-frequency/words.txt @@ -0,0 +1,2 @@ +the day is sunny the the +the sunny is is