The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 08-23-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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.