disciple has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; my $source = shift or &usage(); my $lines_per_file = shift or &usage(); open (my $FH, "<$source") or die "Could not open source file. $!"; open (my $OUT, ">00000000.log") or die "Could not open destination fil +e. $!"; my $i = 0; while (<$FH>) { print $OUT $_; $i++; if ($i % $lines_per_file == 0) { close($OUT); my $FHNEW = sprintf("%08d", $i); open ($OUT, ">${FHNEW}.log") or die "Could not open destinatio +n file. $!"; } } sub usage() { print <<EOF; PROGRAM NAME: Partition File DESCRIPTION: Takes a file and creates many small files out of the large file. EXAMPLE USAGE: partition_file.pl log.txt 1000 PARAMETERS: 1. Source File: File name of the source file to partition. 2. Maximum number of lines per file: The number of lines per file. EOF exit; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Splitting Large File into many small ones.
by Corion (Patriarch) on Dec 08, 2003 at 21:52 UTC | |
|
Re: Splitting Large File into many small ones.
by pg (Canon) on Dec 08, 2003 at 21:55 UTC | |
by disciple (Pilgrim) on Dec 09, 2003 at 04:31 UTC | |
|
Re: Splitting Large File into many small ones.
by Paulster2 (Priest) on Dec 08, 2003 at 21:54 UTC | |
|
Re: Splitting Large File into many small ones.
by disciple (Pilgrim) on Dec 08, 2003 at 22:40 UTC | |
by BrowserUk (Patriarch) on Dec 08, 2003 at 23:45 UTC | |
|
Re: Splitting Large File into many small ones.
by disciple (Pilgrim) on Dec 09, 2003 at 02:16 UTC | |
by BrowserUk (Patriarch) on Dec 09, 2003 at 02:42 UTC |