Ever get a gigantic data file that you needed to chop into small pieces for processing, because the next tool you were passing it to just couldn't handle that much at once? Or maybe a server log that somebody forgot to rotate? Here's the easy solution: pass this one-liner the files you need to subdivide (e.g. error_log), and you'll get out bite-sized files labeled error_log.chunk01, error_log.chunk02 and so forth.

Note that a bite is defined in this case to be 10,000 lines: if you want bigger bites, you can always change that number. Also note that bite #100 will be named error_log.chunl00, if you get that high (which you probably don't want to anyway).

perl -pe '$chnk = "chunk01" if 1 == $.; open (STDOUT, ">", $ARGV . "." + . $chnk++) unless ($. - 1) % 10_000; close ARGV if eof' big_file_on +e big_file_two

In reply to Chunk large data/log files into more manageable pieces by ChemBoy

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.