Created
September 18, 2011 19:08
-
-
Save hrnn/1225418 to your computer and use it in GitHub Desktop.
prints a ramdon line from a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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