Q:

Count files occurrences linux

I want to count the number of times each word in column 3 occurs. Below is the input
IN A three
US B one
LK C two
US B three
US A one
IN A one
US B three
LK C three
US B two
US A two
IN A two
US B two

Output should look like:
IN A three    4
US B one      3
LK C two      5
US B three    4
US A one      3
IN A one      3
US B three    4
LK C three    4
US B two      5
US A two      5
IN A two      5
US B two      5

A:

This can be a way;
$ awk 'FNR==NR{++a[$3]; next} {print $0, a[$3]}' file file
IN A three 4
US B one 3
LK C two 5
US B three 4
US A one 3
IN A one 3
US B three 4
LK C three 4
US B two 5
US A two 5
IN A two 5
US B two 5

Explanation
It loops through the file twice: firstly to fetch data, secondly to print it.

FNR==NR{++a[$3]; next} when looping for the first time, keep track of how many times the 3rd value appears.
{print $0, a[$3]} when looping for the second time, print the line plus the counter value.

To have a nicer output you can also use printf to print a tab after the 3rd column:
{printf "%s\t%s\n", $0, a[$3]}

