Hi
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;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|