make your own fortune

Fortune is a random wisdom-learning game. Using the following way, you can easily make your favorite txt book into fortune-like random display:

Maintain your own fortune datfiles using make shares with us the Makefile script:

POSSIBLE += $(shell ls -1 | egrep -v '\.dat|README|Makefile' | sed -e 's/$$/.dat/g')
all: ${POSSIBLE}
%.dat : %
        @strfile $< $@

as said:

This will look at any file in that directory that isn’t named “README”, “Makefile”, or that doesn’t already end with “.dat”. It will then run strfile on them, resulting in correspondingly named datfiles.

Now, whenever you get a new quote to add to your own fortune files, just cd to your fortune directory, edit the text file, and run “make”. You will then have personal fortune datfiles that you can use with fortune, which you can use by specifying either the path to the textfile, or the directory containing all your fortunes.

However, a fortune file separate lines with ‘%’ character. Suppose you have a txt file with thousands of lines, inserting ‘%’ line by line would be a pain in the neck. You need shell script to automate it. The simple way is to use ‘sed‘. As tought:

sed '/^$/d;G' "filename"

will double space a file which already has blank lines in it. Output file should contain no more than one blank line between lines of text.
then:

sed 's/^/%/' "filename"
insert character % at beginning of each line. This will make your file into fortune-style file ready to 'make'.
I have a chinese poem txt in utf-8 format and can thus be fortuned poem by poem randomly :)