Respuestas:
Puede usar el shufcomando de GNU coreutils . La utilidad es bastante rápida y llevaría menos de un minuto mezclar un archivo de 1 GB.
El siguiente comando podría funcionar en su caso porque shufleerá la entrada completa antes de abrir el archivo de salida:
$ shuf -o File.txt < File.txt
brew install coreutilsy usar /usr/local/bin/gshuf.
cat myfile | perl -MList::Util=shuffle -e 'print shuffle(<STDIN>);' Sin embargo, estoy seguro de lo rápido que funcionaría
Python one-liner:
python -c 'import sys, random; L = sys.stdin.readlines(); random.shuffle(L); print "".join(L),'
Lee todas las líneas de la entrada estándar, las baraja en el lugar, luego las imprime sin agregar una nueva línea final (observe la ,desde el final).
Para OSX se llama al binario gshuf.
brew install coreutils
gshuf -o File.txt < File.txt
Si, como yo, viniste aquí para buscar una alternativa shufpara macOS, úsala randomize-lines.
Instale el randomize-linespaquete (homebrew), que tiene un rlcomando que tiene una funcionalidad similar 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
Olvidé dónde encontré esto, pero aquí está lo shuffle.plque 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;
}
Al menos en ubuntu, hay un programa llamado shuf
shuf file.txt