Based on your criteria here is yet another solution:

#!/usr/bin/perl -w ######################################################### use strict; use Tie::File; my @fin=(); my @fout=(); tie @fin,"Tie::File","bigfile.txt" or die $!; my $fcount=1; for(my $ix=0;$ix<=$#fin;$ix+=30){ my $end = ( $ix+29 <=$#fin ? $ix+29 : $#fin ); my $outfilename = sprintf("litte_file_%0.2d.txt",$fcount); tie @fout,"Tie::File",$outfilename or die $!; for(my $iy=$ix;$iy<=$end;$iy++){ push @fout,$fin[$iy]; } untie @fout; $fcount++; }
Some file sizes for you:
[pberghol@cowdawg splitter]$ wc -l bigfile.txt 500 bigfile.txt [pberghol@cowdawg splitter]$ wc -l litte_file_* 30 litte_file_01.txt 30 litte_file_02.txt 30 litte_file_03.txt 30 litte_file_04.txt 30 litte_file_05.txt 30 litte_file_06.txt 30 litte_file_07.txt 30 litte_file_08.txt 30 litte_file_09.txt 30 litte_file_10.txt 30 litte_file_11.txt 30 litte_file_12.txt 30 litte_file_13.txt 30 litte_file_14.txt 30 litte_file_15.txt 30 litte_file_16.txt 20 litte_file_17.txt 500 total


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

In reply to Re: spliting large file into smaller by blue_cowdawg
in thread spliting large file into smaller 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.