CAN AWK KEEP COUNT

Jonathan I. Kamens jik at athena.mit.edu
Fri Mar 22 21:54:57 AEST 1991


First of all, you don't have to use cut to pass awk the 49th through 100th
columns of the data; awk can figure out what to use itself.  Second, awk is
capable of both splitting strings at specified columns (using substr) and of
keeping a running total.  Something like this:

awk 'BEGIN {
	column1 = column2 = column3 = column4 = column5 = 0;
}
{
	column1 += substr($0,49,10);
	column2 += substr($0,59,12);
	column3 += substr($0,71,10);
	column4 += substr($0,81,10);
	column5 += substr($0,91,10);
}
END {
	printf("%d %d %d %d %d\n", column1, column2, column3, column4, column5);
}'

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik at Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710

P.S. By the way, both substr and the math capabilities of awk are among its
basic functions that are documented in the man page.  If you needed to ask on
the net about them, I think perhaps you need to do a little bit more
documentation reading.



More information about the Comp.unix.questions mailing list