Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env sh
- # Prints a random line from a file
- # Script by @augustohp
- lines_on() {
- file=$1
- wc -l $file | awk '{print $1}'
- }
- random_until() {
- max=$1
- min=1
- echo $(( ($RANDOM % $max) + $min ))
- }
- print_line_in_file() {
- file=$1
- line=$2
- awk "NR==${line}" $file
- }
- if [ -z "$1" ]
- then
- echo "Usage: $0 <file>"
- exit 2
- fi
- # Here be dragons
- print_line_in_file $1 $(random_until $(lines_on $1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement