From 713c9d04db95dd8b3409014fd8f9529d34d993cc Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 31 Jul 2011 01:17:28 +0200 Subject: randline: initial commit --- util/bin/randline | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100755 util/bin/randline (limited to 'util') 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" -- cgit v1.2.3