randline
randline is a command-line to randomize the order of lines fed into the program. The program reads lines of text from stdin and prints them out in randomized order to stdout.
It works similarly to sort -R, but improves sort in two aspects:
- randline can be configured to read and write lines with \0 as terminator. This is helpful in shell scripts where you have to handle file names with spaces.
- The randomization's seed can be either provided as a parameter (to make the randomization deterministic) or will be chosen randomly if omitted.
Examples
- Randomize a list of files:
ls -1 | randline
- Randomize a list of files, but set a fixed random seed of 23:
ls -1 | randline 23
- Randomize a list of files using find and zero-terminated file names:
find -print0 | randline -0
- The same, but with fixed random seed (order of parameters does not matter):
find -print0 | randline 42 -0
find -print0 | randline -0 42
- You can e.g. build a MP3 jukebox with randomly selectes songs to play:
find -iname '*.mp3' -print0 | randline -0 | xargs -0 mplayer
Note that the -print0 and -0 switches take care that the shell does not interprete spaces in file names as separators.
Download
License
This program is distributed under the FreeBSD License (2-clause BSD license).
Copyright 2010 Thomas Fischer. All rights reserved.Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
This project is not affiliated with the FreeBSD project.
Last Updated: 15-Sep-2011 Contact: Thomas Fischer