Skip to content
/ s Public

Sum (or, Silly Shell Script that Shall Summation in an S-expreSSion Style)

Notifications You must be signed in to change notification settings

coffeeburger/s

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

s

Sum or, Slightly Skillful/Solid/Simple/Silly/(whatever) Shell Script that Shall Summation in an S-expreSSion Style with Savvy. (So many S's!)

SYNOPSIS

s [list of numbers]
s [-rv] [-h headertype] [file ...]

DESCRIPTION

s performs one of the following:

  • Sums the list of numbers given as arguments and outputs the result.
  • Reads the specified file, or standard input if no file is specified, then prints a list of numbers summed vertically. When there is only one line of input, sums row-wise.

OPTIONS

-d delimiter : Specify the field delimiter.

-r : Sum by row instead of vertically.

-v : Print the original input and summation result.

-h x|y : Specifies a heading with the given arguments. x for the header row and y for the header column. The specified header row or column is excluded from summation.

EXAMPLES

Sum arguments:

s 14 28
# output: 42

s {1..100}
# output: 5050

Sum by standard input:

cat <<eof |s
> 20
> 22
eof
# output: 42

Sum horizontally when the input is one line.

echo 21 21 |s
# output: 42

If there are 2 or more rows, show the sum for each column.

cat <<eof |s
> 13 6 7
> 8 5 3
> eof
# output: 21 11 10

Execute s again with a pipe, it will print the total sum of all numbers.

cat <<eof |s|s
> 13 6 7
> 8 5 3
> eof
# output: 42

REQUIREMENTS

  • gawk
  • bash

About

Sum (or, Silly Shell Script that Shall Summation in an S-expreSSion Style)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published