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;
In reply to split a file into number of file based on line count by asha80
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |