How can I randomize the lines in a file using standard tools on Red Hat Linux?
I don't have the shuf
command, so I am looking for something like a perl
or awk
one-liner that accomplishes the same task.
Using the shuf Command The shuf utility is a member of the GNU Coreutils package. It outputs a random permutation of the input lines. The shuf command will load all input data into memory during the shuffling, and it won't work if the input file is larger than the free memory.
Ways of using shuf command:Suppose file. txt contains 6 lines, then the shuf command displays the input lines in random order as output. Any number of lines can be randomized by using -n option. This will display any two random lines from the file.
Um, lets not forget
sort --random-sort
shuf
is the best way.
sort -R
is painfully slow. I just tried to sort 5GB file. I gave up after 2.5 hours. Then shuf
sorted it in a minute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With