#! /usr/local/bin/perl use strict; use warnings; # Example data - 85_782 lines, 1_072_787 (words), 10_313_190 bytes - filename: syslog # Split into 3 files: Execution time on a 333MHz Ultrasparc w/1GB RAM less than 5 seconds... # Written by -Sx- o4/22/2oo4 ... # Example command: # perl split_files 3 split_files-TEST my $split_into = shift || 3; my $filename = shift || die "no file name given..."; my $line_cnt; my $counter; my $x; open (ROFILE, "$filename") or die "cannot open $filename $!"; while() { ++$line_cnt; } close (ROFILE) or die "cannot close $filename $!"; open (ROFILE, "$filename") or die "cannot re-read $filename $!"; for ($x=0; $x < $split_into; ++$x) { open (WOFILE, ">$filename.$x") or die "cannot write to $filename.$x $!"; while() { print WOFILE $_; ++$counter; last if ($counter >= ($line_cnt/$split_into)); } $counter = 0; close (WOFILE) or die "cannot close $filename.$x $!"; } close (ROFILE) or die "cannot close $filename $!"; print "Done ... \n\n"; __END__ 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z