SPUG: Sorting a big file

David Dyck david.dyck at fluke.com
Fri Aug 27 16:09:45 CDT 2004


On Fri, 27 Aug 2004 at 12:53 -0700, Dan Ebert <mathin at mathin.com> wrote:

> I have a large file (~1 million lines, ~142MB) which I need to sort (any
> order is fine, just so the lines are in a repeatable order).

Take a look at the File::Sort module from CPAN


NAME
       File::Sort - Sort a file or merge sort multiple files

SYNOPSIS
         use File::Sort qw(sort_file);
         sort_file({
           I => [qw(file_1 file_2)],
           o => 'file_new', k => '5.3,5.5rn', -t => '|'
         });

         sort_file('file1', 'file1.sorted');

DESCRIPTION
       This module sorts text files by lines (or records).
       Comparisons are based on one or more sort keys extracted
       from each line of input, and are performed
       lexicographically. By default, if keys are not given, sort
       regards each input line as a single field.  The sort is a
       merge sort.  If you don't like that, feel free to change
       it.



More information about the spug-list mailing list