tinyapps.org / blog


Randomize lines with custom delimiter #

Arthur de Jong's rl (randomize lines) "reads lines from an input file or stdin, randomizes the lines and outputs a specified number of lines. It does this with only a single pass over the input while trying to use as little memory as possible." It came in handy when I wanted to randomize a collection of quotes which looked like this:
%

Nothing, to my way of thinking, is a better proof of a well ordered mind than a man's ability to stop just where he is and pass some time in his own company.

Seneca

%

There is an old story about a famous rabbi living in Europe who was visited one day by a man who had traveled by ship from New York to see him. The man came to the great rabbi's dwelling, a large house on a street in a European city, and was directed to the rabbi's room, which was in the attic. He entered to find the master living in a room with a bed, a chair, and a few books. The man expected much more. After greetings, he asked, "Rabbi, where are your things?" The rabbi asked in return, "Well, where are yours?" His visitor replied, "But, Rabbi, I'm only passing though," and the master answered, "So am I, so am I."

Jack Kornfield

%

Simplicity of life, even the barest, is not a misery, but the very foundation of refinement.

William Morris

%
Here's how I randomly reordered them with rl, specifying "%" as the delimiter instead of the default newline:

$ rl -d% quotes.txt > randomized_quotes.txt

The latest version is 0.2.7. Install via ./configure && make && make install, or OS X users can grab this binary I compiled under 10.6.

(tags: unix, randomize, lines, text, reorder, rearrange)

/nix | Apr 29, 2010


Subscribe or visit the archives