Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 631
user3144923 Avatar asked Oct 25 '25 06:10

user3144923


2 Answers

awk '{sum+=$1} END{ print sum}'
like image 113
Thorsten Staerk Avatar answered Oct 26 '25 22:10

Thorsten Staerk


This should do the trick:

awk '{s+=$1} END {print s}' file

Or just pipe it into awk with

uniq -c whatever | awk '{s+=$1} END {print s}'
like image 45
Jens Avatar answered Oct 26 '25 22:10

Jens