aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-01 13:27:22 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-01 13:28:26 +1200
commit9666a2fa7bf21db5ad2ed28444cd8db18012cdc7 (patch)
tree9173c5425c526ff3396335ae6ebc998d235e4873
parentChange coffee joke to FSF/SPI/OBSD donate request (diff)
downloaddotfiles-9666a2fa7bf21db5ad2ed28444cd8db18012cdc7.tar.gz
dotfiles-9666a2fa7bf21db5ad2ed28444cd8db18012cdc7.zip
Add rndl(1)
-rw-r--r--README.markdown3
-rwxr-xr-xbin/rndl9
-rw-r--r--man/man1/rnda.12
-rw-r--r--man/man1/rndf.12
-rw-r--r--man/man1/rndi.12
-rw-r--r--man/man1/rndl.119
6 files changed, 33 insertions, 4 deletions
diff --git a/README.markdown b/README.markdown
index 4ceb0c04..52a2d4b0 100644
--- a/README.markdown
+++ b/README.markdown
@@ -304,10 +304,11 @@ Installed by the `install-bin` target:
* `rfct(1)` formats ASCII RFCs.
* `rfcr(1)` does both, displaying in a pager if appropriate, like a
`man(1)` reader for RFCs.
-* Three toy random-number scripts (not for sensitive/dead-serious use):
+* Four toy random-number scripts (not for sensitive/dead-serious use):
* `rndi(1)` gets a random integer within two bounds
* `rnda(1)` uses `rndi(1)` to choose a random argument
* `rndf(1)` uses `rnda(1)` to choose a random file from a directory
+ * `rndl(1)` uses `rndi(1)` to choose a random line from files
* `ax(1)` evaluates an awk expression given on the command line; this is
intended as a quick way to test how Awk would interpret a given expression.
* `ca(1)` prints a count of its given arguments.
diff --git a/bin/rndl b/bin/rndl
new file mode 100755
index 00000000..17118862
--- /dev/null
+++ b/bin/rndl
@@ -0,0 +1,9 @@
+#!/bin/sh
+# Print a random line from argument files
+if [ "$#" -eq 0 ] ; then
+ printf >&2 'rndl: Need at least one filename\n'
+ exit 1
+fi
+lc=$(sed '$=;d' "$@") || exit
+ri=$(rndi 1 "$lc") || exit
+exec sed -- "$ri"'!d' "$@"
diff --git a/man/man1/rnda.1 b/man/man1/rnda.1
index 4537d695..09833927 100644
--- a/man/man1/rnda.1
+++ b/man/man1/rnda.1
@@ -11,6 +11,6 @@ arg1 arg2 arg3
prints a random choice from the given arguments. It uses rndi(1), which is not
a high-quality random number source.
.SH SEE ALSO
-rndf(1), rndi(1), rndn(6)
+rndf(1), rndi(1), rndl(1), rndn(6)
.SH AUTHOR
Tom Ryder <tom@sanctum.geek.nz>
diff --git a/man/man1/rndf.1 b/man/man1/rndf.1
index 95daeccb..a01a1125 100644
--- a/man/man1/rndf.1
+++ b/man/man1/rndf.1
@@ -14,6 +14,6 @@ prints the name a random file (excluding dot files) from the given directory,
defaulting to the current directory. It uses rndi(1), which is not a
high-quality random number source.
.SH SEE ALSO
-rndi(1), rnda(1), rndn(6)
+rndi(1), rnda(1), rndl(1), rndn(6)
.SH AUTHOR
Tom Ryder <tom@sanctum.geek.nz>
diff --git a/man/man1/rndi.1 b/man/man1/rndi.1
index 84f79ff5..b645d504 100644
--- a/man/man1/rndi.1
+++ b/man/man1/rndi.1
@@ -15,6 +15,6 @@ even return the same result if run within the same second. This should not be
used in any sort of security or statistical context. The author wrote it to
support scripts to choose a random background image from a directory.
.SH SEE ALSO
-rnda(1), rndf(1), rndn(6)
+rnda(1), rndf(1), rndl(1), rndn(6)
.SH AUTHOR
Tom Ryder <tom@sanctum.geek.nz>
diff --git a/man/man1/rndl.1 b/man/man1/rndl.1
new file mode 100644
index 00000000..33aa6c87
--- /dev/null
+++ b/man/man1/rndl.1
@@ -0,0 +1,19 @@
+.TH RNDL 1 "August 2016" "Manual page for rndl"
+.SH NAME
+.B rndl
+\- return a low-quality random choice of a random line from files
+.SH SYNOPSIS
+.B rndl
+file
+.br
+.B rndl
+file1 file2 file3
+.br
+.SH DESCRIPTION
+.B rndl
+prints a random line from the files given as arguments, using rndi(1) to choose
+it.
+.SH SEE ALSO
+rndi(1), rnda(1), rndf(1), rndn(6)
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>