forked from pixelb/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd
More file actions
executable file
·43 lines (35 loc) · 1.03 KB
/
add
File metadata and controls
executable file
·43 lines (35 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh
# takes a list of numbers (line separated) 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
paste -s -d+ |
bc # all but last \n --> +
#method 2
#(tr '\n' +; echo 0) |
#bc # \n --> +
#method 3
#tr '\n' + # \n --> +
#sed 's/+$/\
#/' | # last + --> \n
#bc
#method 4
#(
#echo 0
#sed 's/\(.\)$/\1+/' # \n --> +\n
#echo p
#) |
#dc #5 times slower!
#method 5
#awk '{s+=$0} END {print s}'