
:
#######################################################
# prog2 - list the top 10 files by user
#######################################################

# see also mklist
masterlist=/usr/stevei/c/stat/master.list

cat $masterlist |
awk '/^[lbcd]/ { next } # skip special files
{
    #_begin template for stat args: -oidlugpsanw
    mode=$1
    inum=$2
    device=$3

    # the [constructed] idnum must be used when scanning 
    # multiple file systems in order to uniquely 
    # identify the file.
    idnum=sprintf("%s %s", inum, device) 

    links=$4
    uid=$5
    gid=$6
    fsize=$7

    day=$8
    month=$9
    dayofmonth=$10
    time=$11
    year=$12
    # access=sprintf("%s %s %s %s %s", 
    #    day, month, dayofmonth, time, year)

    fname=$13
    #_end template

    # add minimum file size ?
    # if ( size < xx ) next

    # do not recount linked files

    if ( unique[ idnum ] != 1 )
        printf("%8s %10d %s\n", uid, fsize, fname)
    unique[ idnum ] = 1
}' | sort -rn |
awk 'BEGIN {
  max_count=10 # list only 10 files for each user
  count=1
}
{
  cur_id=$1
  if ( cur_id == last_id )
      count += 1
  else
      count=1   

  if ( count < max_count )
      print

  last_id=cur_id
}'
exit 0

