Sunday, January 4, 2009

split separate large file into small chunk files

split separate large file into small chunk files



#!C:\Perl\bin\perl.exe

foreach my $fileName (@ARGV) {
$i = 0;

open FILE, " open FILE2, ">C:/tmp/" . $fileName . $i or die $!;

while () {
# assigning each line to $str
$str = $_;

# 100000 lines per file
if ( $i%100000 == 0 ) {
$itmp = $i/100000;
close FILE2;
open FILE2, ">C:/tmp/" . $fileName . $itmp or die $!;
}

print FILE2 $str;

$i++;
}

close FILE;
close FILE2;
}

No comments: