Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 19 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 https://raw.github.com/Homebrew/homebrew/go/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)

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

Your Answer

 
discard

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.