What's wrong with this Bourne shell script?
Tom Christiansen
tchrist at convex.COM
Fri Aug 17 02:26:34 AEST 1990
In article <FPB.90Aug16005419 at ittc.ittc.wec.com> fbresz at 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 at 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]
More information about the Comp.unix.questions
mailing list