summaryrefslogtreecommitdiffstats
path: root/util/bin/randline
diff options
context:
space:
mode:
authortv <tv@also>2011-07-31 01:17:28 +0200
committertv <tv@also>2011-07-31 01:17:28 +0200
commitb992445601d4bd3520c8dc16f8e352b157fec555 (patch)
treeb30ce24f68eec8b2046bc986e9cd61d3777f049d /util/bin/randline
parent77cc36ffb4e63e3bb4692db139b57c364bf9b4ed (diff)
randline: initial commit
Diffstat (limited to 'util/bin/randline')
-rwxr-xr-xutil/bin/randline12
1 files changed, 12 insertions, 0 deletions
diff --git a/util/bin/randline b/util/bin/randline
new file mode 100755
index 00000000..cd9476e7
--- /dev/null
+++ b/util/bin/randline
@@ -0,0 +1,12 @@
+#! /bin/sh
+#
+# choose a line randomly.
+#
+set -euf
+
+lines="`cat`"
+count=`echo "$lines" | wc -l`
+random=`od -An -t u8 -N 8 /dev/urandom`
+choice=`echo "$random % $count + 1" | bc`
+
+echo "$lines" | sed -n "${choice}p"