Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f93a55beae
Fetching contributors…

Cannot retrieve contributors at this time

executable file 40 lines (32 sloc) 0.977 kb
#!/bin/sh
# takes a list of numbers (line seperated) and prints the total
# License: LGPLv2
# Note the input to this will probably come from `cut`,
# so a couple of tips on cut:
# 1. columns from `ls -l` are delimited by a variable
# number of spaces. You can ignore this fact by
# squeezing said spaces with a `tr -s ' '` before
# you input to cut -d' '. Generally find is much
# better for printing inode info than ls.
# 2. You should probably always use the -s option to
# cut, so that it doesn't output lines that do not
# contain the delimiter
tr -cd '[.\n0-9]' | # only leave numbers
sed '/^$/d' | # delete any blank lines
#method 1
(tr '\n' +; echo 0) |
bc # \n --> +
#method 2
#tr '\n' + # \n --> +
#sed 's/+$/\
#/' | # last + --> \n
#bc
#method 3
#(
#echo 0
#sed 's/\(.\)$/\1+/' # \n --> +\n
#echo p
#) |
#dc #5 times slower!
#method 4
#awk '{s+=$0} END {print s}'
Jump to Line
Something went wrong with that request. Please try again.