compute mean from two files

December 5, 2011 at 09:59:09
Specs: Linux i686
HI

I'm having trouble to do that script in awk. I would like to compute the mean of two colomns from two diffent files just like that

[CODE]file 1

4 1
5 2
6 3

[/CODE]


[CODE]file 2

1 1
2 2
3 3

[/CODE]


[CODE]output

(4+1) /2 1
(5+2)/2 2
(6+3)/2 3

[/CODE]


thanks a lot


See More: compute mean from two files

Report •

#1
December 5, 2011 at 13:14:36
a way ..... # use nawk with Solaris

awk ' BEGIN { cnt=1;
   while ( getline < "file1.txt" > 0 )
      myarr[cnt++]=$1
}
{
if(NR in myarr)
   printf("%2.2f, %d\n", ((myarr[NR] + $1)/2), $2)

} ' file2.txt


Report •
Related Solutions


Ask Question