Append awk results into file or array

for a in {1..100}
do
awk '{ sum+=$a} END {print sum}' a=$a file1 > file2
done

I know I will get only one number if following the code above, how can I get 100 sum numbers in file2?

Please use

```text
 and 
```

tags around any posted code.

Is this what you are after:

for a in {1..100}
do
    awk '{ sum+=$a} END {print sum}' a=$a file1
done > file2

or

awk '{for(i=1;i<=100;i++) sum+=$i} END {$0=x; for(i=1;i<=100;i++) $i=sum; print }' file1 > file2
1 Like

Thanks~