Skip to content

Instantly share code, notes, and snippets.

@hrnn
Created September 18, 2011 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrnn/1225418 to your computer and use it in GitHub Desktop.
Save hrnn/1225418 to your computer and use it in GitHub Desktop.
prints a ramdon line from a file
#!/bin/bash
if [ $# -ne 1 ]
then
echo "Syntax: $0 FILE"
echo $0 - display a random line from FILE.
exit 1
fi
RAND=`od -d -N2 -An /dev/urandom`
LINES=`cat "$1" | wc -l`
LINE=$(( RAND % LINES + 1 ))
head -$LINE $1 | tail -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment