in reply to Split files into chunks of $n lines
use strict; use warnings; die "Usage $0 from to" unless @ARGV == 2; my $to = pop @ARGV; $to .= ".%03d"; my $count = 1; my $fh; while (<>) { if ($. % 4000 == 1) { unless ($. == 1) { close $fh or die; } open $fh, ">", sprintf $to, $count ++ or die; } print $fh $_; } close $fh or die;
|
|---|