Skip to content

Instantly share code, notes, and snippets.

@rochefort
Created July 7, 2011 22:46
Show Gist options
  • Select an option

  • Save rochefort/1070727 to your computer and use it in GitHub Desktop.

Select an option

Save rochefort/1070727 to your computer and use it in GitHub Desktop.
split_file.pl
#!/usr/bin/perl
use strict;
use warnings;
my $file = 'test.txt';
my $split_line = 3;
my $cnt = 0;
my $file_cnt = 0;
open IN, $file or die $!;
while (<IN>){
if ($cnt % $split_line == 0) {
open OUT, "> file$file_cnt.txt" or die $!;
print OUT;
$file_cnt ++;
} else {
print OUT;
}
$cnt ++;
}
close IN;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment