I have a pattern file called pattern.txt containing the following
abc
def
I want to do a count, but have it display the count value preceeding each line like grep -n
so
grep -n -f pattern.txt would show
1:abc
2:def
3:abc
4:abc
5:def
What I would like to do is have grep count the number of occurances in the file and place that value at the begining of the output so it would look like
3:abc
2:def
3 means abc occured 3 times in the file
2 means def occured 2 times in the file
Is there a function or a clever way to achieve this?