Tuesday, September 15, 2009

Counting the number of occurrences of each line in a file

To count the number of occurrences of each line in Linux you can use the following command:
sort input_file | uniq -c > output_file

You may want to ignore the case and then apply the count:
cat input_file | tr '[:upper:]' '[:lower:]' | sort | uniq -c > output_file

No comments:

Post a Comment