dakid
March 3, 2008, 9:06pm
1
I do have a file (named as templist) which looks like this one:
00450000.000000 00402300.000000 00040000.000000 00020000.000000 00020000.000000 00020000.000000 00020000.000000
and I want to make a script that adds this using AWK or FOR.
I tried using awk using the command
but it just returns the value of the first variable 450000.
please help me to modify my command.
thanks
$ echo 00450000.000000 00402300.000000 00040000.000000 00020000.000000 00020000.000000 00020000.000000 00020000.000000 \
| awk -v RS=" " '{sum=sum+$1;printf("sum: %.0f\n",sum)}'
sum: 450000
sum: 852300
sum: 892300
sum: 912300
sum: 932300
sum: 952300
sum: 972300
dakid
March 3, 2008, 10:04pm
3
thanks for this
this outputs:
is it possible to output only the final result in the file "sum: 972300"
remove the cat. Use the END {} block
awk -v RS=" " '{sum=sum+$1} END { .... }' templist > total
dakid
March 3, 2008, 10:26pm
5
i tried using this one:
but its giving me an error
please help me in fixing this.
xtest> awk '{ for (i=1;i<=NF;i++)sum+=$i ; printf("sum: %.0f\n",sum)}' dakid
sum: 972300
dakid
March 3, 2008, 11:28pm
7
thank you all for great help.
dakid
June 3, 2008, 12:01pm
8
it seems that there is an issue if there are more numbers of lines added... seems that the output becomes zero.
please help me
dakid
June 3, 2008, 8:46pm
9
kindly disregard this inquiry... i've found out that the code works well, but the problem is somewhere else