Hi Monks, I have a perl script that almost does what I want but not quite. I'm trying to divide a CVS file into multiple files of equal size. What I have divides almost all of the files into ones that are equal sizes but always leaves one larger file. I'm guessing it's the first or last file that's written in the series. If you could have a look at the code below and tell me what I'm doing wrong/have missed I'd greatly appreciate it. Thanks .
#!/usr/bin/perl -w use strict; use warnings; #split large files mkdir "split_files"; open (FH, "all_tags2.csv") or die "Could not open source file. $!"; my $i = 0; while (1) { my $chunk; print "process part $i\n"; open(OUT, ">split_files/all_tags2$i.csv") or die "Could not open d +estination file"; $i ++; if (!eof(FH)) { read(FH, $chunk, 10000); print OUT $chunk; } if (!eof(FH)) { $chunk = <FH>; print OUT $chunk; } close(OUT); last if eof(FH); }
In reply to split large CSV file >9.1MB into files of equal size that can be opened in excel by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |