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 UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #19 (permalink)  
Old 03-07-2007
anbu23 anbu23 is offline
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Code:
awk ' { if ( $0 ~ /^Grid-ref/ ) {
        if( tot == 0 ) { tot = NR }
        else {
                tot = NR - tot -1;
                for( i = 1; i <= nf ; ++i )
                        printf("%.1f ", arr[i] / tot );
                printf("\n")
                for( i = 1; i <= nf ; ++i )
                        arr[i] = 0
                tot = NR;
        }
        print
}
else
        for( i = 1; i <= NF ; ++i )
                arr[i] = arr[i] + $i
nf=NF
}
END {
tot = NR - tot
for( i = 1; i <= nf ; ++i )
        printf("%.1f ", arr[i] / tot );
printf("\n")
}
' file
Reply With Quote