Equivalent of gnu `sort -R` on OSX?

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.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

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)


On OS X, if you don't want to install homebrew (but you really should), you could use perl or ruby:

perl -MList::Util -e 'print List::Util::shuffle <>'

or

ruby -e 'puts STDIN.readlines.shuffle'