Risposte:
Puoi usare il shufcomando da GNU coreutils . L'utilità è piuttosto veloce e richiederebbe meno di un minuto per mescolare un file da 1 GB.
Il comando seguente potrebbe funzionare nel tuo caso perché shufleggerà l'input completo prima di aprire il file di output:
$ shuf -o File.txt < File.txt
brew install coreutilse usa /usr/local/bin/gshuf.
cat myfile | perl -MList::Util=shuffle -e 'print shuffle(<STDIN>);' Sono sicuro di quanto sarebbe veloce però
Python one-liner:
python -c 'import sys, random; L = sys.stdin.readlines(); random.shuffle(L); print "".join(L),'
Legge tutte le righe dall'input standard, le mescola sul posto, quindi le stampa senza aggiungere una nuova riga finale (notare ,la fine).
Per OSX viene chiamato il binario gshuf.
brew install coreutils
gshuf -o File.txt < File.txt
Se come me sei venuto qui per cercare un'alternativa a shufmacOS, allora usa randomize-lines.
Installa il randomize-linespacchetto (homebrew), che ha un rlcomando con funzionalità simili 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
Ho dimenticato dove l'ho trovato, ma ecco quello shuffle.plche 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;
}
Almeno in Ubuntu, c'è un programma chiamato shuf
shuf file.txt