shuffle

I would like to be able to randomize some data (I fear a firewall may be a little too smart) - so I need to "randomize" my datastream which in this case is a file.

Using Perl !! I create a Symbol

alias shuffle="perl -MList::Util=shuffle -e 'print shuffle(<STDIN>);'"

Then I can pipe data in

If the input file (data.txt) is

1
2
3
4

Then

shuffle < data.txt

Then running 3 times yields

4
2
3
1
(pe36) timothyhseed@Tim-i5 GeoIP $ shuffle <data.txt 
2
3
4
1
(pe36) timothyhseed@Tim-i5 GeoIP $ shuffle <data.txt 
1
2
3
4

Python version

If you must stick with python

shuf() { python -c '
import sys, random, fileinput; from signal import signal, SIGPIPE, SIG_DFL;    
signal(SIGPIPE, SIG_DFL); lines=[line for line in fileinput.input()];   
random.shuffle(lines); sys.stdout.write("".join(lines))
' "$@"; }

Create a bash function called shuf, then do your python.