I've been tasked with rearranging lines from many large files into another set of large files, without any duplicates. However, these files are so big this is not as easy as it seems. The total size of all the files is in the gigs, so simply pulling all the lines into memory is not an option. The current solution I have is to first convert all the files into fixed-length lines via printf "%50s". Then, grab a (unused) random number based on the total number of lines, and use sysseek to go to that line and grab it, then write to the new file. This works but is very slow: research indicated it was the sysseek that was really slow, which is understandable due to the size of the file. It also seems to draw more and more memory as time goes on - if it keeps increasing, it will max out the RAM before getting even 25% done. Any ideas or suggestions to speed things up? The lines must be randomly ordered, but only appear once in the final output files. I tried putting all the post printf output into one *big* file to read from, and tried breaking it up into many 500M files, but each was still very slow. Perl is version 5.6.1.

In reply to Strategy for randomizing large files via sysseek by Anonymous Monk

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.