asha80 has asked for the wisdom of the Perl Monks concerning the following question:
I have one file with 500 lines in it. i want to split that file into 5 file each should contain 100 lines.
i used delimiter after every hunder lines and i am able to split file into 5 files.Now what i want is...
Instead of delimiter i want to count number lines in a file.then split that file qually into 5 files..Please help me in doing this one
spliting file code using delimiter.#!/usr/bin/perl my $fil_count = 0; my $delim = 'test'; open IN, '< test1.txt' or die "Can't open in.txt: $!\n"; open OUT, '> Out0.txt' or die "Can't write to out0.txt: $!\n"; while (<IN>) { if (/^(.*?)$delim(.*)$/) { print OUT $1 if $1; close OUT; $fil_count++; open OUT, '> Out' . $fil_count . '.txt' or die "Can't write to out +${fil_count}.txt: $!\n"; print OUT $2 if $2; } else { print OUT $_; } } close IN;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: split a file into number of file based on line count
by moritz (Cardinal) on May 13, 2009 at 06:58 UTC | |
by Utilitarian (Vicar) on May 13, 2009 at 09:06 UTC | |
by Bloodnok (Vicar) on May 13, 2009 at 10:02 UTC | |
by ww (Archbishop) on May 13, 2009 at 12:01 UTC | |
by Bloodnok (Vicar) on May 13, 2009 at 13:58 UTC | |
by JavaFan (Canon) on May 13, 2009 at 09:50 UTC | |
|
Re: split a file into number of file based on line count
by thiagu_mvt (Sexton) on May 13, 2009 at 07:21 UTC | |
|
Re: split a file into number of file based on line count
by imrags (Monk) on May 13, 2009 at 07:57 UTC |