awk related questin

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blessedgirl
    New Member
    • Jan 2010
    • 3

    awk related questin

    how can i get the sum and get average of records of files using awk programming

    i have several output files like this

    file 1
    year col1 col2 col3 col4
    1 0.4 0.1 0.3 0.8
    1 0.3 0.2 0.9 2
    2 0.1 0.3 0.8 0.7
    2 0.2 0.4 0.9 0.7
    3 0.4 0.3 0.8 0.3
    3 0.2 0.4 0.4 0.2
    4 0.8 0.4 0.8 0.3
    4 0.5 0.4 0.5 0.5

    file 2
    year col1 col2 col3 col4;
    1 0.4 0.1 0.3 0.8
    1 0.3 0.2 0.9 2
    2 0.1 0.3 0.8 0.7
    2 0.2 0.4 0.9 0.7
    3 0.4 0.3 0.8 0.3
    3 0.2 0.4 0.4 0.2
    4 0.8 0.4 0.8 0.3
    4 0.5 0.4 0.5 0.5

    file 3
    year col1 col2 col3 col4
    1 0.4 0.1 0.3 0.8
    1 0.3 0.2 0.9 2
    2 0.1 0.3 0.8 0.7
    2 0.2 0.4 0.9 0.7
    3 0.4 0.3 0.8 0.3
    3 0.2 0.4 0.4 0.2
    4 0.8 0.4 0.8 0.3
    4 0.5 0.4 0.5 0.5

    and i want the average out puts of all the records of a files to be summed and averaged in to one file and looks like this

    year col1 col2 col3 col4
    1
    1
    2
    2
    3
    3
    4
    4
    5
    5
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Please clarify.
    1. Do you a want separate output file for each input file; or do you want a single output file that combines the information from all the input files.
    2. You say you want to "sum and average" the records, but your example output looks like you merely want to print the first column of each record and throw away the rest of the data.

    Comment

    • blessedgirl
      New Member
      • Jan 2010
      • 3

      #3
      i just want to get the average of each points of (year1, col1), (year1,col2), (year1,col3),(y ear1,col4), (year2,col1), (year2,col2), (year2, col3), (year2,col4), (year3,col1)... ............... ..... (year4, col4).


      and each point should be a sum of 50 files points. all the 50 files are same replicates with the same content and form

      Comment

      Working...