I can't make heads or tail of your version, bu this works for me.

#line.pl
#!/usr/local/bin/perl

open (FILE, $ARGV[0] ) or die "$!\n";
my $count = <FILE>;
chomp($count);

$line = 1;
while ( <FILE> ) {
   print  if $line++ > $count;
}

#line.txt
3
line1
line2
line3
line4
line5
line6
line7

[cgalpin@pooh perl]$ ./line.pl line.txt
line4
line5
line6
line7


hth
charles

On Mon, 22 Nov 1999, gnielson wrote:

> I am trying to write a perl script that will read a number from a file,
> use that as a counter, and only print out lines above that counter number.
> So if the number is 5 and the file is 10 lines, only the last 5 lines
> would be printed.
> 
> The problem is when it prints out it misses one line, so instead of
> printing 5 lines it will print the last 4 lines. 
> 
> Any help much appreciated.
> 
> # $text is the counter variable
> 
> open(FD,"$file") || die "Can not open $file";
>         while(<FD>) {
> 
>                 my $lineNo = "0";
>                 while ($line = <FD>)
> { 
>                 print "lineNo is $lineNo and text is $text\n";
> 
>                 next if ($lineNo < $text);
>                 print $line;
> }
> }
> close FD;


-- 
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.

Reply via email to