Summing up values of rows of numbers

data file contains

failed=24
error=23
error=163
failed=36
error=903

i need to get a total count of each value above. i'm looking for the most efficient method to do this as the datafile i provided is just a sample. the actual data can be several hundred thousands of lines.

so from the above data, the desired result should be:

error=1089
failed=60

notice how i got rid of the duplicates and only kept the value and then added up the value?

can awk do this efficiently?

thank you

What have you tried so far?

try:

awk -F"=" '/failed/{sum1+=$2};/error/{sum2+=$2}END{print "failed="sum1"\n""error="sum2}' file
1 Like

Another method:

awk -F= '{a[$1]+=$2};END{for (x in a) print x FS a[x]+0}' file
1 Like