I want to read a file line by line as following:
while read line;
do
set -- $line
c=$# #count words and save as $c
r=$(( RANDOM%c ))
#here i'd like to get the word on position r from $line
done < words.txt
I know, I can get word 1 as following:
set -- $line
echo $1
But how can I replace 1 with the integer saved in $r?