Randomly sort the lines in a file

There are times when you need to randomly order the lines in a file. Here’s a script to do just that:

#!/usr/bin/perl -w

use strict;
use List::Util 'shuffle';

my @lines = <>;
print shuffle( @lines );

Related posts:

  1. Verifying file integrity with debsums
    After upgrading my Ubuntu server, some security applications grumped about changed contents of some common binaries. Just to be safe, I wanted to verify them explicitly with debsums, but debsums......
  2. Recursive sort-by-modification-time
    This certainly isn’t rocket science, but it also is certainly not something you want to type more than once. find . -type f -printf '%T@\t%p\n' | sort -n | cut......
  3. Dailed-in Rails script/console with pretty printing and history
    Edit (as root) your /etc/irbrc: # Some default enhancements/settings for IRB, based on # http://wiki.rubygarden.org/Ruby/page/show/Irb/TipsAndTricks   unless defined? ETC_IRBRC_LOADED   # Require RubyGems by default. require 'rubygems'   begin require......
  4. Maildir auto-archive
    If you’ve got your mail sitting on some server and in Maildir format, and you’ve used Outlook’s “Auto Archive” feature, you might wish that your inbox (and subdirectory contents) could......

This entry was posted in Technical HOWTOs and tagged . Bookmark the permalink.

2 Responses to Randomly sort the lines in a file

  1. See also the `sort -R` and `shuf` commands

  2. Darlon says:

    Thanks, man.

    It really helped me with my Mac.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Additional comments powered by BackType