The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #7 (permalink)  
Old 08-28-2007
baghera baghera is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 23
Quote:
Originally Posted by vgersh99 View Post
I don't quot understand why you need all the coding when you can do it all in awk:

nawk -f bag.awk myFile

bag.awk:

Code:
{
   for(i=1; i<=NF; i++)
       sum[i] += $i
   nf=NF
   nr=NR
}

END {
    for(i=1; i<=nf; i++)
        print sum[i]/nr
}
Huh? I tried your script but I only get 1.5

when I have list:

1
2
1
2

The output should be:
1
2

Or on the same row 1 2

As I described above. But there should also be the possibility to tell how many columns there should be.

Last edited by baghera; 08-28-2007 at 03:05 PM..