//View Tip #557
» Command line currency conversion
» Tar remote dir over SSH
» Find last modified files on a filesystem
» Check a bash script without executing
Jonas
Similar Tips
» .. revisited» Command line currency conversion
» Tar remote dir over SSH
» Find last modified files on a filesystem
» Check a bash script without executing
Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
The bash shell has a variable called $RANDOM, which outputs a pseudo-random number every time you call it. This allows you to randomize the lines in a file for example:
In other words, put a random number on every line, sort the file, then take off the random numbers.
for i in `cat unusual.txt`; do echo "$RANDOM $i"; done | sort | sed -r 's/^[0-9]+ //' > randorder.txt
In other words, put a random number on every line, sort the file, then take off the random numbers.
Comments
Add your comment
Comments are currently disabled
#1
There is a error in your coded. Replace the single quote with double so it reads "$RANDOM $i"
Posted 2009-03-10 11:19:53
Thanks Jonas for pointing that out, must have missed that one in moderation! The command is corrected now.
Posted 2009-03-10 11:25:07

