The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Special Forums > Filesystems, Disks and Memory
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 12-05-2006
reborg's Avatar
reborg reborg is offline
Administrator
 
Join Date: Mar 2005
Location: Ireland
Posts: 3,513
Untested, and untidy

Code:
awk -F, 'NR==1 {  printf "%15s", $3
                         for ( i = 4 ; i <= NF; i++ ) { 
                             printf "%8s", $i 
                         }
                         printf "\n"
                         next
                      }                                               
                     {  ind[$3] = NF 
                         for ( i = 4 ; i <= NF; i++ ) {
                             result[$3,i] += $i 
                         }
                      }
            END {
                      for ( j in ind ) { 
                         printf "%15s",j 
                         for ( i = 4 ; i <= ind[j]; i++) { 
                             printf "%8d", result[j,i]
                         }
                         print line}
                   }' datafile
Reply With Quote