in reply to Re^7: Sort big text file - byte offset - 50% there (Added code)
in thread Sort big text file - byte offset - 50% there
#!/usr/bin/perl -w use strict; use Date::Calc qw(Mktime); open (BIGLOG, "< D:/Logs/biglog.unsorted.log") || die "Cannot open unsorted log $!"; my( $offset, @index ) = 0; while (<BIGLOG>){ my $epoch = ( /^\s*#/ or /^\s\n/ or $_ !~ /^\s*\d/ ) ? 0 : Mktime( unpack 'A4xA2xA2xA2xA2xA2', $_ ); push @index, pack 'NN', $epoch, $offset; $offset = tell BIGLOG; } @index = sort {$a cmp $b} @index; open (OUTFILE, "> D:/Logs/biglog.sorted.log") || die "Cannot write sor +ted log $!"; while (@index){ print OUTFILE readline_n(\*BIGLOG, shift @index); } close BIGLOG; close OUTFILE; exit; sub readline_n{ my( $fh, $line) = @_; seek ($fh, unpack( 'N',substr( $line, 4, 4 )), 0) || warn "Problem + seeking to $line $!\n"; scalar <$fh> }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: Sort big text file - byte offset
by msalerno (Beadle) on Aug 31, 2006 at 21:05 UTC | |
by BrowserUk (Patriarch) on Aug 31, 2006 at 22:46 UTC | |
by BrowserUk (Patriarch) on Sep 02, 2006 at 15:45 UTC |