Hello,
I need to take a random word from a flat text file with words in it seperated by spaces.
The code I am using, always gives me the first word. Can anyone please shed some light on this. Here's my code.
Thanks
echo table roof ceiling jar computer monitor keyboard carpet > wordfile
file_name=wordfile \# $file_name is the name of file that you select a random word
num_words=\`wc -w $file_name | cut -d " " -f 1\`
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
echo "$word" > hidd
fi