Tuesday, July 28, 2009

How to extract a particular group of sentences in a file using PERL commands?

If there are fifty lines in a file. i must extract the middle ten line and must stored it in another file using PERL commands

How to extract a particular group of sentences in a file using PERL commands?
#!/usr/bin/perl -w





use strict;





open( INPUTFILE, "input.txt" ) ;


my $startCaptureLine = 10;


my $numLinesToCapture = 10;


my $curLine = 1;


my $capturedLines = "";


foreach (%26lt;INPUTFILE%26gt;) {


if( $curLine %26gt;= $startCaptureLine


and $curLine %26lt;= $startCaptureLine + $numLinesToCapture - 1 ) {


$capturedLines .= $_ ;


}


++$curLine;





}


print "$capturedLines";





exit 0;

sim cards

No comments:

Post a Comment