I am trying to select one random word from a file, any ideas on how to do this as i have only manged to generete the random number?
#!/usr/bin/ksh
# random_word.sh: selects one random word from a file
# usage: random_word.sh file_name
file_name=$1 # $file_name is the name of file that you select a random word
num_words=`wc -w $file_name | cut -d " " -f 1`
#echo $RANDOM
rand_word=`expr "$RANDOM" % $num_words + 1`
i=0
for word in `cat $file_name`
do
i=`expr $i + 1`
if [ $i = $rand_word ]
then
printf "$word"
exit 0
fi
done