Get Random Text From A File


A simple way to get some random text from a file

#!/bin/bash
# get random text from a file
file="file"
IFS=$'\n'
set -- $(<$file)
size=${#@}
randint=$((RANDOM%size+1))
numline=0
while read -r myine
do
  (( numline++ ))  # or numline=$((numline+1))
    case "$numline" in
       $randint) echo "$myline";;
    esac
done < $file

Tags: linux bash