aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-12-27 18:00:02 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-12-27 18:00:02 +1300
commitc4e80884b5c8ee0e2fbabaa867586d29e1ace9ef (patch)
tree69999e18d91294a2b822b16e2932acacfdb9283a
parentMerge branches 'port/bsd/*' (diff)
downloaddotfiles-c4e80884b5c8ee0e2fbabaa867586d29e1ace9ef.tar.gz
dotfiles-c4e80884b5c8ee0e2fbabaa867586d29e1ace9ef.zip
Add max(1df) and min(1df)
-rw-r--r--.gitignore2
-rw-r--r--Makefile10
-rw-r--r--README.markdown4
-rw-r--r--bin/max.awk10
-rw-r--r--bin/min.awk10
-rw-r--r--man/man1/max.1df19
-rw-r--r--man/man1/min.1df19
7 files changed, 70 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index d7a435fa..110f8c4b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,9 +2,11 @@ bin/csmw
bin/ddup
bin/gwp
bin/han
+bin/max
bin/mean
bin/med
bin/mftl
+bin/min
bin/mode
bin/rfct
bin/rndi
diff --git a/Makefile b/Makefile
index 97fec6e5..da6b043a 100644
--- a/Makefile
+++ b/Makefile
@@ -71,9 +71,11 @@ all : bin/csmw \
bin/ddup \
bin/gwp \
bin/han \
+ bin/max \
bin/mean \
bin/med \
bin/mftl \
+ bin/min \
bin/mode \
bin/rfct \
bin/rndi \
@@ -93,9 +95,11 @@ clean distclean :
bin/ddup \
bin/gwp \
bin/han \
+ bin/max \
bin/mean \
bin/med \
bin/mftl \
+ bin/min \
bin/mode \
bin/rfct \
bin/rndi \
@@ -193,9 +197,9 @@ install-bash-completion : install-bash
install -pm 0644 -- bash/bash_completion "$(HOME)"/.config/bash_completion
install -pm 0644 -- bash/bash_completion.d/* "$(HOME)"/.bash_completion.d
-install-bin : bin/csmw bin/ddup bin/gwp bin/han bin/mean bin/med bin/mftl \
- bin/mode bin/rfct bin/rndi bin/sd2u bin/sec bin/slsf bin/su2d bin/tot \
- bin/unf bin/uts install-bin-man
+install-bin : bin/csmw bin/ddup bin/gwp bin/han bin/max bin/mean bin/med \
+ bin/mftl bin/min bin/mode bin/rfct bin/rndi bin/sd2u bin/sec bin/slsf \
+ bin/su2d bin/tot bin/unf bin/uts install-bin-man
install -m 0755 -d -- "$(HOME)"/.local/bin
for name in bin/* ; do \
[ -x "$$name" ] || continue ; \
diff --git a/README.markdown b/README.markdown
index 109af073..777d5dd1 100644
--- a/README.markdown
+++ b/README.markdown
@@ -394,9 +394,11 @@ Installed by the `install-bin` target:
* `unf(1df)` joins lines with leading spaces to the previous line.
Intended for unfolding HTTP headers, but it should work for most RFC
822 formats.
-* Four simple aggregators for numbers:
+* Six simple aggregators for numbers:
+ * `max(1df)` prints the maximum.
* `mean(1df)` prints the mean.
* `med(1df)` prints the median.
+ * `min(1df)` prints the minimum.
* `mode(1df)` prints the first encountered mode.
* `tot(1df)` totals the set.
* `ap(1df)` reads arguments for a given command from the standard input,
diff --git a/bin/max.awk b/bin/max.awk
new file mode 100644
index 00000000..11d4efd9
--- /dev/null
+++ b/bin/max.awk
@@ -0,0 +1,10 @@
+# Get the maximum of a list of numbers
+{
+ if (NR == 1 || $1 > max)
+ max = $1
+}
+END {
+ if (!NR)
+ exit(1)
+ print max
+}
diff --git a/bin/min.awk b/bin/min.awk
new file mode 100644
index 00000000..c58a3a8f
--- /dev/null
+++ b/bin/min.awk
@@ -0,0 +1,10 @@
+# Get the minimum of a list of numbers
+{
+ if (NR == 1 || $1 < min)
+ min = $1
+}
+END {
+ if (!NR)
+ exit(1)
+ print min
+}
diff --git a/man/man1/max.1df b/man/man1/max.1df
new file mode 100644
index 00000000..28431da4
--- /dev/null
+++ b/man/man1/max.1df
@@ -0,0 +1,19 @@
+.TH MAX 1df "September 2016" "Manual page for max"
+.SH NAME
+.B max
+\- print the maximum of a list of numbers
+.SH SYNOPSIS
+printf '%u\\n' 3 55 17 |
+.B max
+.br
+.B max
+file
+.br
+.B max
+file1 file2
+.SH DESCRIPTION
+.B max
+collects all the newline-delimited numbers given as input, and prints the
+maximum.
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>
diff --git a/man/man1/min.1df b/man/man1/min.1df
new file mode 100644
index 00000000..e3279d3b
--- /dev/null
+++ b/man/man1/min.1df
@@ -0,0 +1,19 @@
+.TH MIN 1df "September 2016" "Manual page for min"
+.SH NAME
+.B min
+\- print the minimum of a list of numbers
+.SH SYNOPSIS
+printf '%u\\n' 182 2 22 |
+.B min
+.br
+.B min
+file
+.br
+.B min
+file1 file2
+.SH DESCRIPTION
+.B min
+collects all the newline-delimited numbers given as input, and prints the
+minimum.
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>