I have command to list system process by memory usage:

ps -A --sort -rss -o comm,pmem


Which list a table like

COMMAND         %MEM
firefox         28.2
chrome           5.4
compiz           4.8
atom             2.5
chrome           2.3
Xorg             2.3
skype            2.2
chrome           2.0
chrome           1.9
atom             1.9
nautilus         1.8
hud-service      1.5
evince           1.3


I would like to get total memory share per programs instead of per process of same programs. So I could get output like

COMMAND         %MEM
firefox         28.2
chrome          11.6
compiz           4.8
atom             4.4
Xorg             2.3
skype            2.2
nautilus         1.8
hud-service      1.5
evince           1.3


I thought about using awk, which I don't know much. Ended up with something like:

ps -A --sort -rss -o comm,pmem | awk -F "\t" '
{processes[$0] += $1;}
{End
for(i in processes) {
  print i,"\t",processes[i];
}
}'


But it didn't work.

How can I correct this?


Question: How can toddlers expend seemingly boundless energy when they eat so little?
Answer: They don't eat little. Consider the volume of milk / food they consume as a ratio of their weight. Quite the contrary they are ravenous machines and their consumption is much higher than an average adult. All cellular energy comes from the hydrolysis of ATP, and the production of ATP comes from the breakdown of glucose. The glucose comes from a sugar found in breast milk, called lactose.