Counting occurrence of all words in a file

Hi, Given below is the input file:

Given below is what the output file should look like:

I know how to count the occurrence of 1 word from a file, but not all of them. Can someone help please? An explanation on the code if possible will be much appreciated :slight_smile:

Thanks in advance.

sort inputfile | uniq -c