An Obsession with Everything Else

http://www.derrickschneider.com/atom.xml

Thursday, July 19, 2007

Writing Mantras Screensaver

I realized, while looking at a recent round of edits from one of my editors, that I don't always remember all my mantras for editing and reworking text: "Specifics trump generalities" and so forth.

I decided to put them into a screen saver as a reminder. I wanted something that would print a random line from a text file I created.

I hit pay dirt with the Message screen saver, which allows you to put up an arbitrary string or the output of a shell command. After a bit of Internetting, I figured out how to use awk and pipes to get the effect I wanted.

Here's the shell command that the screen saver runs each time it changes messages: awk 'BEGIN{srand();}{ print rand() "\t" $0 }' ~/writing-mantras.txt | sort -n | head -n 1 | cut -f2-

Translation: Read each line of the writing-mantras.txt file and put a random number in front of each one. Pipe the output through a numerical sort, pipe that through head to get the top line, and then pipe that through cut to get rid of the random number you slapped on the beginning.

Neat.

0 Comments:

Post a Comment

<< Home