To sum several values in column from file we can use paste command and bash arithmetic expressions
$ echo $(($(paste -s -d'+' nums)))
I've always used tr to glue the values into one line, but the remaining '+' sign must be removed:
$ echo $(($(cat nums | tr '\n' '+' |sed 's/.$//')))
Or with awk:
$ awk '{s+=$1}; END { print s}' nums
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment