What's wrong with this Bourne shell script?

Mark Harrison harrison at necssd.NEC.COM
Thu Aug 16 04:36:10 AEST 1990


In article <FPB.90Aug13191108 at ittc.ittc.wec.com>,
   fpb at ittc.wec.com (Frank P. Bresz) writes:
> 	Where is Jon's addcol.  I tried to write one a while back and kept
> screwing it up.  I would like to see a working version.

Here is a simple one in awk.  Replace $4 with your column number.

		awk '{ tot += $4} END{print tot}'
			      ^^
If you put this into a shell script called addcol, you can say

		awk '{ tot += $'$1'} END{print tot}'

and invoke it by
		addcol 4

Example:  How many bytes in my files?

		ls -l c* | awk '{ tot += $4} END{print tot}'
		ls -l c* | addcol 4

Hope this helps!
-- 
Mark Harrison             harrison at necssd.NEC.COM
(214)518-5050             {necntc, cs.utexas.edu}!necssd!harrison
standard disclaimers apply...



More information about the Comp.unix.questions mailing list