c60c-4ay@e260-1b.berkeley.edu (Raja S Kushalnagar) (12/16/89)
I have a large file having lots of quotes, in the format: %% ...... quote ............ %% ...... quote ............ %% and so on. I could write a C program to print a quote at random. But I was wondering if it could be done with Unix commands or awk alone. Could it? Raja S Kushalnagar. raja@{athena, ocf, soda} | root@athena | c60c-4ay@web | laba-1ad@web ***************************************************************************** Raja "The Duke" S Kushalnagar. raja@soda.berkeley.edu laba-1ad@web.berkeley.edu raja@athena.berkeley.edu raja@ocf.berkeley.edu c60c-4ay@web.berkeley.edu root@athena.berkeley.edu
karish@forel.stanford.edu (Chuck Karish) (12/16/89)
In article <1989Dec16.064319.21721@agate.berkeley.edu> c60c-4ay@e260-1b (Raja S Kushalnagar) wrote: |I have a large file having lots of quotes, in the format: |%% |...... quote ............ |%% |...... quote ............ |%% | |and so on. I could write a C program to print a quote at random. But I was |wondering if it could be done with Unix commands or awk alone. Could it? The `fortune' program was written for exactly this purpose. Available from uunet by anonymous FTP (comp.sources.games/volume1/fortune/*) Chuck Karish karish@mindcraft.com (415) 323-9000 karish@forel.stanford.edu
andrew@tvcent.uucp (Andrew Cowie) (12/20/89)
In article <1989Dec16.064319.21721@agate.berkeley.edu> c60c-4ay@e260-1b (Raja S Kushalnagar) writes: > (lines deleted) >and so on. I could write a C program to print a quote at random. But I was >wondering if it could be done with Unix commands or awk alone. Could it? Yes. A while ago a small script was posted that got a random quote from a file of star trek quotes. Here is the script: -------- # # fortune.sh - uses $$ for rand. # a=`expr $$ % 400` expr " $a" : '.*\(.....\)' | \ join -t% -o 2.2 - $HOME/bin/stquotes -------- It operates on a file of the following format: (there were 400 originally, I figured that you didn't need the whole file :-) -------- 0%Star Trek Lives! 1%Schshschshchsch. 1% -- The Gorn, "Arena," stardate 3046.2. 2%Live long and prosper. 2% -- Spock, "Amok Time," stardate 3372.7. 3%Totally illogical, there was no chance. 3% -- Spock, "The Galileo Seven," stardate 2822.3. 4%All your people must learn before you can reach for the stars. 4% -- Kirk, "The Gamesters of Triskelion," stardate 3259.2. 5%We have found all life forms in the galaxy are capable of 5%superior development. 5% -- Kirk, "The Gamesters of Triskelion," stardate 3211.7. -------- Note that quotes can be of any length. I hope this works for what you are trying to do. > Raja S Kushalnagar. -- Andrew F. Cowie at TVC Enterprises, Toronto, Canada. uunet!mnetor!lethe!tvcent!andrew andrew@tvcent.uucp