I am new to perl. I would like to open a file and print 2,6,10,14.. etc lines of that file content. How to do it? I amm able to open a file and print the contetnts as below:
Is it possible to skip $line or jump every 4 $line(ie) the lines in that file. Please let me know.
Thanks.
Code:
#!usr/bin/perl
$data_file = "test.txt";
open(EXPORTFILE, $data_file) || die("Could not open file!");
print "Opened $data_file\n";
$counter = 0;
while(($line=<EXPORTFILE>) && ($counter<100)) {
if($counter == 0) {
print "Skip $counter \n";
$counter++;
next;
}
print "COUNTER: $counter \n";
chomp($line);
print "$line \n";
$counter++;
}
close EXPORTFILE;
exit(0);
Thanks.
Comment