aboutsummaryrefslogtreecommitdiff
path: root/bin/rndl
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 /bin/rndl
parentChange coffee joke to FSF/SPI/OBSD donate request (diff)
downloaddotfiles-9666a2fa7bf21db5ad2ed28444cd8db18012cdc7.tar.gz
dotfiles-9666a2fa7bf21db5ad2ed28444cd8db18012cdc7.zip
Add rndl(1)
Diffstat (limited to 'bin/rndl')
-rwxr-xr-xbin/rndl9
1 files changed, 9 insertions, 0 deletions
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' "$@"