How to get the count of duplicate strings in a set using grep, uniq and awk in unix?

StackOverflow https://stackoverflow.com/questions/15996859

  •  03-04-2022
  •  | 
  •  

سؤال

I have a very large set of strings, one on every line of a file. Many strings occur more than one times in the file at different locations.

I want a frequency count of the strings using unix commands like awk, grep, uniq and so on. I tried few combinations but it didn't work.

what is the exact command to get the frequency count?

هل كانت مفيدة؟

المحلول

To count the occurrences of lines in a file the simplest thing to do is:

$ sort file | uniq -c 
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top