Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The GNU sort text utility features a non-standard -R option to randomize input lines.

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

share|improve this question
up vote 27 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.

ruby -e "$(curl -fsSL"

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 page:

Randomize lines (opposite of | sort)

share|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

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 <>'


ruby -e 'puts STDIN.readlines.shuffle'
share|improve this answer

Use shuf or sort from coreutils package, but then you've to add /usr/local/bin to your PATH in ~/.bashrc file, for example:

export PATH=/usr/local/sbin:/usr/local/bin:$PATH

Alternatively you can try ex:

ex -s +"%s/^/\=reltimestr(reltime())[-2:].' '" +"sort n" +"%s/^\S* //" +%p -cq! /dev/stdin

Source: How to shuffle a list in vim?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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