Results 1 to 3 of 3

Thread: help

  1. #1
    Join Date
    Jun 2004
    Posts
    2

    Unanswered: help

    I have 100 matrix files. Each one contains the same number of columns
    and rows, where each cell contains some number.

    How can I build one total matrix where its cells are the respective sum
    of all 100 positions from the other matrix ?

    3 files (2x2) case,

    file 1 file 2 file 3
    1 0 1 1 0 0
    0 1 1 1 0 1

    the result must be

    2 1
    1 3

    any ideas ???

    Thxs !

  2. #2
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    if your input files are file1, file2, file3 ... file100

    nawk -f brazil.awk file*

    here's the brazil.awk
    Code:
    {
      for(i=1; i <= NF; i++)
        sum[FNR,i] += $i
      nf=NF;
    }
    
    END {
      for (i=1; i <= FNR; i++)
        for(j=1; j <= nf; j++)
           printf("%d%s", sum[i,j], (j != nf) ? OFS : "\n");
    }

  3. #3
    Join Date
    Jun 2004
    Posts
    2

    thank you !

    Awesome !!!!

    Thanks a lot !!!!!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •