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;
In reply to Sort Large Files by Velaki
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |