Question: I need to find the 5 most popular words in a random text, with a bash command. I was trying to make different combinations between `cat`, `wc`, `uniq`, `sort` and `tail`, but couldn't get to anything. Either my output would be a single word, or the text itself, or the wordcount of the text... I should be missing smth...

Is it even possible with a one-liner? Should I approach the problem with smth "a level up", like `for-do`?

F.e. as input: [this random text](http://www.lipsum.com/feed/html) (I've got other texts for my data, but they're too large to show here), and output... well, the 5 most used words (I don't know which ones they are currently :D ).

Answer: 
Does awk count?

```
BEGIN {
    RS=FS                                  # separate words on separate records
    PROCINFO["sorted_in"]="@val_num_desc"  # set sort order to pick most frequent
} 
{
    gsub(/[^a-zA-Z]/,"")                   # remove non-letters
    a[tolower($0)]++                       # convert to lower case and count words
} 
END {
    for(i in a) {                          # go thru array in frequency order
        print i,a[i]                       # print
        if(++j==5); exit                   # exit in five
    }
}
$ awk -f this.awk lorem.txt
vitae 10
in 10
quis 9
eget 9
nunc 9

```
```
cat words | perl -pe 's/[\W+]/\n/g' | sort | uniq -c | sort -nr  | head -n6
111
 10 vel
  8 ut
  8 turpis
  8 sit
  8 erat

```

sort -n6 because it prints whitespace as top-1 entry