commit 0847f2755eb2ea28d2df75f842d942a12fb90ced
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Wed, 25 Nov 2020 14:29:01 +0100
Add min, max, mean, README, and Makefile
Diffstat:
A | Makefile | | | 41 | +++++++++++++++++++++++++++++++++++++++++ |
A | README | | | 3 | +++ |
A | max | | | 11 | +++++++++++ |
A | mean | | | 10 | ++++++++++ |
A | min | | | 11 | +++++++++++ |
5 files changed, 76 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -0,0 +1,41 @@
+.POSIX:
+
+NAME = mathtools
+VERSION = 0.1.0
+
+# paths
+PREFIX = /usr/local
+MANPREFIX = ${PREFIX}/man
+DOCPREFIX = ${PREFIX}/share/doc/${NAME}
+
+SCRIPTS = mean
+
+MAN1 = ${SCRIPTS:=.1}
+DOC = \
+ LICENSE\
+ README
+
+install:
+ # installing executable files and scripts.
+ mkdir -p "${DESTDIR}${PREFIX}/bin"
+ cp -f ${SCRIPTS} "${DESTDIR}${PREFIX}/bin"
+ for f in ${SCRIPTS}; do chmod 755 "${DESTDIR}${PREFIX}/bin/$$f"; done
+ # installing documentation files.
+ mkdir -p "${DESTDIR}${DOCPREFIX}"
+ cp -f ${DOC} "${DESTDIR}${DOCPREFIX}"
+ for d in ${DOC}; do chmod 755 "${DESTDIR}${DOCPREFIX}/$$d"; done
+ # installing manual pages for general commands: section 1.
+ mkdir -p "${DESTDIR}${MANPREFIX}/man1"
+ cp -f ${MAN1} "${DESTDIR}${MANPREFIX}/man1"
+ for m in ${MAN1}; do chmod 644 "${DESTDIR}${MANPREFIX}/man1/$$m"; done
+
+uninstall:
+ # removing executable files and scripts.
+ for f in ${SCRIPTS}; do rm -f "${DESTDIR}${PREFIX}/bin/$$f"; done
+ # removing example files.
+ for d in ${DOC}; do rm -f "${DESTDIR}${DOCPREFIX}/$$d"; done
+ -rmdir "${DESTDIR}${DOCPREFIX}"
+ # removing manual pages.
+ for m in ${MAN1}; do rm -f "${DESTDIR}${MANPREFIX}/man1/$$m"; done
+
+.PHONY: install uninstall
diff --git a/README b/README
@@ -0,0 +1,3 @@
+Tools to perform common mathematical operations in UNIX pipes
+
+Author: Anders Damsgaard <anders@adamsgaard.dk>
diff --git a/max b/max
@@ -0,0 +1,11 @@
+#!/usr/bin/awk -f
+{
+ for (i=0; i<NF; i++)
+ if ($i > max[i])
+ max[i] = $i
+}
+END {
+ for (i=0; i<NF; i++)
+ printf("%g\t", max[i])
+ printf("\n")
+}
diff --git a/mean b/mean
@@ -0,0 +1,10 @@
+#!/usr/bin/awk -f
+{
+ for (i=0; i<NF; i++)
+ sum[i] += $i
+}
+END {
+ for (i=0; i<NF; i++)
+ printf("%g\t", sum[i]/NR)
+ printf("\n")
+}
diff --git a/min b/min
@@ -0,0 +1,11 @@
+#!/usr/bin/awk -f
+{
+ for (i=0; i<NF; i++)
+ if ($i < min[i])
+ min[i] = $i
+}
+END {
+ for (i=0; i<NF; i++)
+ printf("%g\t", min[i])
+ printf("\n")
+}