With a little side of applesauce...

Thursday, April 24, 2008

BASH - add numbers in a file

Here is a cool solution for adding numbers in BASH, (here grep'ing web access stats for 2007):
#!/bin/sh

set -- `< $@` ## for multiple files use: set -- `cat "$@"`
q=$*
printf "%s\n" $(( ${q// / + } ))


http://cfaj.freeshell.org/shell/tuesday-tips/#tt-2004-06-22

No comments: