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,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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sort Large Files
by Limbic~Region (Chancellor) on Jan 05, 2005 at 21:22 UTC | |
by Velaki (Chaplain) on Jan 06, 2005 at 01:20 UTC | |
|
Re: Sort Large Files
by Anonymous Monk on Jan 06, 2005 at 12:06 UTC | |
by merlyn (Sage) on Jan 06, 2005 at 13:13 UTC | |
by Anonymous Monk on Jan 06, 2005 at 14:02 UTC | |
by merlyn (Sage) on Jan 06, 2005 at 14:17 UTC | |
by Anonymous Monk on Jan 06, 2005 at 14:40 UTC | |
| |
by jdporter (Paladin) on Mar 21, 2005 at 04:19 UTC |