No joke about that sort! It flies. I am only having one problem with the script. For some reason, it throws a warning while printing the sorted log. According to the output of warn, its always on the last line of the unsorted log.

One more question, it's about vec. I have not been able to find any good guides on using it. If I implemented it, would I be able to reduce my memory footprint? Does anyone have a good link with a explanation of the function? Something like perlpacktut but for vec? Thanks again. Here is the updated script with the new sort and old warning.

#!/usr/bin/perl -w use strict; use Date::Calc qw(Mktime Today_and_Now Delta_DHMS); my @starttime = Today_and_Now; print "Begin Index\n"; open (BIGLOG, "< D:/Logs/biglog.unsorted.log") || die "Cannot open log\n"; my @index; while (<BIGLOG>){ my $offset = tell BIGLOG; my $epoch = ( /^\s*#/ or /^\s\n/ or $_ !~ /^\s*\d/ ) ? 0 : Mktime( unpack 'A4xA2xA2xA2xA2xA2', $_ ); push @index, pack 'NN', $epoch, $offset; } print "\nIndexed ". @index ." Lines in "; printf "%02d Days, %02d Hours, %02d Minutes, %02d Seconds\n", Delta_DH +MS( @starttime, Today_and_Now ); print "Begin Sort\n"; my @startsort = Today_and_Now; @index = sort {$a cmp $b} @index; print "Sorted ". @index ." Lines in "; printf "%02d Days, %02d Hours, %02d Minutes, %02d Seconds\n", Delta_DH +MS( @startsort, Today_and_Now ); open (OUTFILE, "> D:/Logs/biglog.sorted.log") || die; foreach (@index){ my $byte = unpack( 'N',substr( $_, 4, 4 )); print OUTFILE readline_n(\*BIGLOG, $byte ) || warn unpack( 'N', substr( $_, 0, 4 )).":".unpack( 'N',substr( +$_, 4, 4 )).$!; } close OUTFILE; close BIGLOG; print "\nTotal runtime:\t\t"; printf "%02d Days, %02d Hours, %02d Minutes, %02d Seconds\n", Delta_DH +MS( @starttime, Today_and_Now); exit; sub readline_n{ my( $fh, $line) = @_; seek $fh, $line, 0; scalar <$fh> }

In reply to Re^4: Sort big text file - byte offset - 50% there (Added code) by msalerno
in thread Sort big text file - byte offset - 50% there by msalerno

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.