Search code examples
scriptingawkuniq

sum occurrence output of uniq -c


I want to sum up occurrence output of "uniq -c" command. How can I do that on the command line?

For example if I get the following in output, I would need 250.

 45 a4
 55 a3
  1 a1
149 a5

Solution

  • awk '{sum+=$1} END{ print sum}'