Hi All,
I need to print the sum of numbers from different files.
Input files:
file1.out
10
20
30
file2.out
10
20
30
i want the sum of the numbers from each row from each file.
in this example, i desire to get
10+10
20+20
30+30
Any help with awk. Thanks a lot.
mirni
2
awk 'NR==FNR{a[NR]=$1; next}{print a[FNR]+$1}' file1.out file2.out
1 Like
paste -d + file1.out file2.out|bc
1 Like
Thanks Mirni, how i can do the same for 1000s of files.
---------- Post updated at 03:43 PM ---------- Previous update was at 03:39 PM ----------
Thanks vgersh99. the simple code works. but i have too many files that paste doesn't work.
then follow mirni's suggestion with the wild-carded file names:
awk '{print a[FNR]+=$1}END{for(i=1;i in a;i++) print a}' myFiles*
1 Like
vgersh99's has bug, here is the update:
awk '{a[FNR]+=$1}END{for(i=1;i in a;i++) print a}' myFiles*
1 Like