in reply to Splitting a text file
$ split --lines=1000 --numeric-suffixes=1 --suffix-length=5 --addition +al-suffix=NR.txt /the/file ''
Even in Perl, I think you have too much code for so little work. One doesn't need to open the input file oneself, it is simpler to pipe the content from the shell and read from STDIN in Perl. One doesn't need to loop over the input oneself, -n already does that. $. contains the current line number, $_ contains the current line content, see perlvar.
</the/file perl -MIO::File -ne' my $nr = 1+int($./1_000); $handles[$nr] = IO::File->new(sprintf("%05dNR.txt", $nr), "w") unl +ess defined $handles[$nr]; $handles[$nr]->print($_); '
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Splitting a text file
by farang (Chaplain) on Mar 20, 2013 at 17:03 UTC |