The GNU sort text utility features a non-standard -R option to randomize input lines (presumably by sorting on a hash).

OSX sort does not have this extension. Is there similar functionality available in another text filter?

link|improve this question
feedback

1 Answer

up vote 1 down vote accepted

If you want, you can install GNU sort through GNU's coreutils package over Homebrew, which is a package manager for OS X.

Running this would install Homebrew.

/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"

Then just follow the installation instructions. When Homebrew is installed, run

brew install coreutils

This will install GNU sort as gsort, so you can use it like sort on any GNU Linux.


Alternatively, have a look at these Stack Overflow questions, which mention a couple of methods:

How can I randomize the lines in a file using a standard tools on Redhat Linux
How can I shuffle the lines of a text file in Unix command line?

Or take a look at this commandlinefu.com page:

Randomize lines (opposite of | sort)

link|improve this answer
The homebrew option works, as would the linked awk or perl constructions (though I imagine they are slower.) The rest are no go, as they are GNU-only. – phs Sep 12 '11 at 18:05
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.