sumcol - a shell script to find the sum of a particular column

Created by Gareth Coates on Mon, 12/02/2019 - 07:34
Published URL:
https://www.ibm.com/support/pages/node/1118127
1118127

How To


Summary

Here is a useful script I picked up off the internet some time ago.

Objective

Banner_AIX_Linux
It finds the sum of a particular column, you use it as a filter, ie: pipe something into it and it gives you an output.

Environment

#  SumCol - sum of a column
#
#SYNOPSIS
#  SumCol N <data
#
#DESCRIPTION
#  Add up column N1 of stdin.  If you pipe the output of "ls  -l"  to
#  this,  it  will  add  up  the  sizes,  which  are in column 4, our
#  default.  You can specify the column for other kinds of files.
#
#BUGS
#  There's a better version available in perl; awk is obsolete.
#
#AUTHOR
#  John Chambers <jc@trillian.mit.edu>
 
if [ $# -lt 1 ];then set 4;fi
awk '{s += $'$1'} END {print s}'

Additional Information

You can contact me: 

Document Location

Worldwide

[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"HW1A1","label":"IBM Power Systems"},"Component":"","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF016","label":"Linux"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}}]

Document Information

Modified date:
03 May 2021

UID

ibm11118127