I don't get that kind of output with
ls -l but assuming you do, the following ought to work.
Code:
ls -l | awk '{ tot[$2] += $1 } END { for (t in tot) printf "%s\t%i\n", t, tot[t] }'
Requesting
ls to sort the output is unnecessary, if you require chronological output order, some additional tricks will be needed. The array loop in awk
for (x in y) traverses the keys of
y in unpredictable order.
Also the sample output you posted doesn't seem to agree with the input. I get the following
Code:
Feb 4593
May 1332
Apr 3131
Mar 2565
Did I misunderstand your requirement, or is the sample output wrong? Looks like you accidentally summed
Mar and
May into the same category.