Count the number of occurances for multiple files

I have some text files as shown below. I would like to add the values of each string. Your help would be appreciated!!

file1.txt

  SUS  2
  PRS  2
  ALI  1
  PRS  1
  GLK  2 

file2.txt

PRS  3
GLK  6
SUS  18

Desired output

SUS  20
PRS  6
ALI  1
 GLK  2

Total - 29

Try:

awk '{a[$1]+=$2}END{for (i in a) print i,a}' *.txt
1 Like

Addendum to bartus11's fine code:

END {for (i in a) {print i,a;Total+=a}; print "Total - ", Total}
1 Like