in reply to spliting large file into smaller
Based on your criteria here is yet another solution:
Some file sizes for you:#!/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++; }
[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
|
|---|