Lubos Rendek

The only solution is determination.

How to Calculate Column Sum With Bash

| Comments

Simple bash to sum a dollar price column.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ cat cost 
$14.99
$13.95
$11.85
$10.90
$7.95
$7.95
$7.88
$7.35
$17.30
$15.99
$10.55
$10.17
$9.69
$11.95
$12.95

First remove “$” dollar sign, format and calculate with bc:

1
2
$ cat cost | sed 's/\$//' | paste -sd+ | bc
171.42

Comments