I'm quite new to bash and its syntax, therefore I would like to know how to sort a list to get the total number for an inventory of our hard drives.
Example is below. We have many servers and many hard drives from different vendors and models.
How would you count them together based on the numbers and not the occurrence of their name.
ST8000NC0002: 8
ST900MM0168: 1
ST900MM0168: 1
ST9300603SS: 3
ST9300605SS: 4
ST9500620SS: 3
WD1003FBYX: 7
WD1500HLFS: 4
WD9001BKHG: 3
WD9001BKHG: 3
WD9001BKHG: 4
WD9001BKHG: 4
Desired output:
ST8000NC0002: 8
ST900MM0168: 2
ST9300603SS: 3
ST9300605SS: 4
ST9500620SS: 3
WD1003FBYX: 7
WD1500HLFS: 4
WD9001BKHG: 14
awk '{a[$1]+=$2}END{for(k in a)print k,a[k]}' file | sort