Respostas:
Você pode usar o shufcomando do GNU coreutils . O utilitário é bastante rápido e levaria menos de um minuto para embaralhar um arquivo de 1 GB.
O comando abaixo pode funcionar no seu caso, porque shufirá ler a entrada completa antes de abrir o arquivo de saída:
$ shuf -o File.txt < File.txt
brew install coreutilse use /usr/local/bin/gshuf.
cat myfile | perl -MList::Util=shuffle -e 'print shuffle(<STDIN>);' Estou nota certeza o quão rápido seria executado embora
One-liner do Python:
python -c 'import sys, random; L = sys.stdin.readlines(); random.shuffle(L); print "".join(L),'
Lê todas as linhas da entrada padrão, embaralha-as no local e as imprime sem adicionar uma nova linha final (observe a ,partir do final).
Para OSX, o binário é chamado gshuf.
brew install coreutils
gshuf -o File.txt < File.txt
Se como eu, você veio aqui para procurar uma alternativa shufpara o macOS, então use randomize-lines.
Instale o randomize-linespacote (homebrew), que possui um rlcomando com funcionalidade semelhante a shuf.
brew install randomize-lines
Usage: rl [OPTION]... [FILE]...
Randomize the lines of a file (or stdin).
-c, --count=N select N lines from the file
-r, --reselect lines may be selected multiple times
-o, --output=FILE
send output to file
-d, --delimiter=DELIM
specify line delimiter (one character)
-0, --null set line delimiter to null character
(useful with find -print0)
-n, --line-number
print line number with output lines
-q, --quiet, --silent
do not output any errors or warnings
-h, --help display this help and exit
-V, --version output version information and exit
Esqueci onde encontrei isso, mas aqui está o shuffle.plque eu uso:
#!/usr/bin/perl -w
# @(#) randomize Effectively _unsort_ a text file into random order.
# 96.02.26 / drl.
# Based on Programming Perl, p 245, "Selecting random element ..."
# Set the random seed, PP, p 188
srand(time|$$);
# Suck in everything in the file.
@a = <>;
# Get random lines, write 'em out, mark 'em done.
while ( @a ) {
$choice = splice(@a, rand @a, 1);
print $choice;
}
Pelo menos no ubuntu, há um programa chamado shuf
shuf file.txt