These five lines were whipped up to sort a massive file on a date field styled MM/DD/YY. It's based on a cross between a GRT and ST, with my own little enhancement. Rather than loading the entire file into memory and then taking references to in-memory elements, the program records in-file positions, and then prints out the file as read at those locations.

Hope you find it useful,
-v

Update: jdporter reminded me it's "GRT" not "GSR". Thanks!

# An evil collection of one-liners to make this five-line # script which sorts a file by a date field. It's designed # for massive files, and indexes directly into the file. open(FD,"data") || die; my ($loc,@a) = (tell(FD)); push(@a,[$loc,(split /\|/)[4]]),$loc = tell(FD) while(<FD>); # 4 is th +e datefield seek(FD,$_,0), $_ = <FD>, print for map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [$_->[0], sprintf "%04d%02d%02d",(split /\//,$_->[1])[2,0,1]] +} @a; close FD;

In reply to Sort Large Files by Velaki

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.