11/7 Is there a shell command that will unsort (randomize) a file,
like the way sort does on a line-by-line basis? I don't need any
mathematical randomizing, just want to mix up my input lines
occasionally. tia.
\_ ~mconst/bin/shuffle
\_ i have some short code to do this. if the file is "large" [+32k ll]
it's somewhat tricky to do ... need a good random generator.
like perl's default doenst have enough seed values. why do
people ask stuff like this anonymously? --psb
\- this looks really slow to me:
/bin/time ./rand-mconst.pl < /tmp/infile > /dev/null
real 46.9
/bin/time ./rand-psb.pl < /tmp/infile > /dev/null
real 4.3
\_ What do you expect? One's an algorithm, one's a one line
hack.
\_ my stupid shell script that works fine for small files:
#!/bin/sh
awk 'BEGIN { srand() }{ print rand(),$0 }' $1 \
|sort|sed 's/^[^ ]* //'
\-I dont think this is portable to "classic awk" ... but
gawk is probably good enough. --psb
\- btw, i just stumbled, er shuffled, on to:
perldoc -q shuffle --psb |