Sunday, 14 December 2008

summing multiple file contents

Open three files tmp, tmp1 and tmp2 with once column each and do a sum of all the numbers of all the colums

E.g:
tmp tmp1 tmp2

1 4 7
2 5 8
3 6 9

paste tmp tmp1 tmp2 | awk '{sum+=$1;sum1+=$2;sum2+=$3} END{printf("%15.0f+%15.0f+%15.0f\n",sum,sum1,sum2)}' | bc

45

No comments:

Post a Comment

Tweets by @sriramperumalla