Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!cs.utexas.edu!uunet!convex!convex.COM From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.unix.questions Subject: Re: What's wrong with this Bourne shell script? Message-ID: <105009@convex.convex.com> Date: 16 Aug 90 16:26:34 GMT References: <1990Aug14.171056.17982@iwarp.intel.com> Sender: news@convex.com Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 29 In article fbresz@ittc.wec.com writes: [chiding of Randal deleted] > That would be fine if I had or wanted pearl. I was under the >impression that Jon's addcol was an awk script (I think that's where the >original thread came from anway) in which the -# was the column you wanted >to add and it would magically add up the numbers in column 1 or 7 or >whatever column you wanted under argumentalized control instead of having >separate scripts for each possible set of columns you want to add. You mean perl, but anyway.... usage: addcol field_number as in 'ls -l | addcol 5' #!/bin/sh field=$1 shift awk "{sum += \$$field;}END {print sum}" $* If you want to bullet-prove it against bad args, you can do more checking --tom -- Tom Christiansen {uunet,uiucdcs,sun}!convex!tchrist Convex Computer Corporation tchrist@convex.COM "UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." [gwyn]