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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk- adding columns

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'd like some help adding columns. { s += $1 }
END { print "sum is", s, : I'm not sure how to use this can someone give me an example please.
 
Just as you posted.........


#------------------ file.txt ------------------
1 2
3 4
5 6
7 8
9 10

#------------------ sum.awk --------------------

{ s1+=$1; s2+=$2 }

END { printf("Sum col1->[%d] Sum col2->[%d]\n", s1, s2); }

#----------------

nawk -f sum.awk file.txt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top