Posted by dandriff on Tuesday June 24, 2008@10:16AM
One-liners for randomizing the order of lines in a file:
Using only the Bash command line:
cat dead.letter | while read -r line; do echo "$RANDOM $line"; done | sed 's/^/0000/' | sed 's/^0*\([0-9]\{5\}[ ].*$\)/\1/' | sort | sed -r 's/^[0-9]+ //'
Using Perl:
perl -e '$filename="dead.letter";use List::Util "shuffle";open FILE,"<$filename" or die("unable to open $filename for reading\n");print shuffle();'
Even shorter with Perl:
cat dead.letter | perl -e '@a=<>;while(@a){print splice(@a,rand(@a),1)}'