Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Awk: sum on a column range

Status
Not open for further replies.

metaltree

Technical User
Nov 27, 2006
28
0
0
CA
Hello,

I need to sum the values of several columns but want to avoid the $1+$2+$3...+$100 syntax.
I tried the command below, but apparently I'm doing something wrong.


Code:
$ cat infile
1       2       3
4       5       6

wanted result
Code:
6
15

Code:
$ awk -F "\t" '{x=0; for (i=1; i<=NF; i++); x = x + $i; print x }' infile
0
0
 
awk '{x=0;for(i=1;i<=NF;i++)x=x+$i;print x}' infile

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top