![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| $random | relle | Shell Programming and Scripting | 6 | 07-11-2008 05:59 AM |
| how to create random no between 10 to 40 in C | useless79 | High Level Programming | 5 | 08-19-2007 08:51 PM |
| Random | keyvan | Shell Programming and Scripting | 8 | 05-24-2007 12:11 PM |
| Getting a random file | davidY | Shell Programming and Scripting | 6 | 01-01-2007 05:03 AM |
| random in ksh | pascalbout | AIX | 1 | 01-04-2006 10:53 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Code:
#!/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
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|