I wrote a quick program to sort a log file, at the time it worked great, but now the log files are getting to be 80 - 100 MB before the sort is run. When I run my program I'm starting to get out of memory errors. At the rate we are growing the log files will grow by ~50 MB a month, and I can't split the log files to anything smaller. I know I could write a buble sort and keep the contents on the disk, but I don't want to thrash the disk that much. Does anyone know of a good way to sort large files?
Here is an example of the log file format:
[05:24:50.7] : Start 963365840704 0 Fri Feb 16, 2001 17:24
+:50.704 CST select FOO from BAR where foo_bar = 578525 order by FO
+O
[05:24:50.7] : End 963365840704 15
[05:24:50.7] : Start 982365890719 1 Fri Feb 16, 2001 17:24
+:50.719 CST select BAR from FOO where var_foo = 578525 order by BA
+R
[05:24:50.7] : End 982365890719 0
I just need the sql statements, but they need to be sorted. Below is the code I wrote:
print sort {$a cmp $b} map {(split /\t/,$_)[4]} grep {(substr ($_,15,5
+) eq "Start")?1:0}<>;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.