![]() |
|
|
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 select text file ranamed | topic32428285 | Shell Programming and Scripting | 4 | 04-29-2009 02:52 PM |
| Retrieving random numbers out of a text file | nistleloy | UNIX for Dummies Questions & Answers | 13 | 12-14-2008 04:28 PM |
| Can a shell script pull the first word (or nth word) off each line of a text file? | tricky | Shell Programming and Scripting | 5 | 08-17-2006 07:29 AM |
| Creating flat text file (ASCII) | Wdonero | UNIX for Dummies Questions & Answers | 5 | 04-20-2005 06:33 AM |
| how to get rid of blank line in a flat text file | xfang | Shell Programming and Scripting | 11 | 05-28-2003 04:08 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
| Bookmarks |
| Tags |
| random words |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|