Shortest command to calculate the sum of a column of output on Unix?

Posted by Andrew on Stack Overflow See other posts from Stack Overflow or by Andrew
Published on 2008-11-17T15:05:17Z Indexed on 2010/06/02 10:53 UTC
Read the original article Hit count: 202

Filed under:
|
|
|

I'm sure there is a quick and easy way to calculate the sum of a column of values on Unix systems (using something like awk or xargs perhaps), but writing a shell script to parse the rows line by line is the only thing that comes to mind at the moment.

For example, what's the simplest way to modify the command below to compute and display the total for the SEGSZ column (70300)?

ipcs -mb | head -6
IPC status from /dev/kmem as of Mon Nov 17 08:58:17 2008
T         ID     KEY        MODE        OWNER     GROUP      SEGSZ
Shared Memory:
m          0 0x411c322e --rw-rw-rw-      root      root        348
m          1 0x4e0c0002 --rw-rw-rw-      root      root      61760
m          2 0x412013f5 --rw-rw-rw-      root      root       8192

© Stack Overflow or respective owner

Related posts about unix

Related posts about math