Re: Get a section of a file



lac wrote:

I am trying to write a function that gets only a section of a file.
When the file is too big, I want the user to be able to select the
section that he wants to read from the file by specifying the first and
the last line of a file that he wants to read.

So the function I want to write should take in three arguments:
filename, start and end. It will return the lines from the file with
filename from line "start" to line "end". Here is the function
prototype:


proc GetFile {filename start end} { ... }

Can somebody help me with this, I cannot figure out how to select only
the specific lines from the file?

For example, let say we have the file input.txt below:

Adriano
Kaka
Ronaldinho
Ronaldo
Edmilson
Ze Roberto
Cafu
Roberto Carlos


WIth this file: "GetFile input.txt 2 5" should return:

Ronaldinho
Ronaldo
Edmilson
Ze Roberto

perl -ne'BEGIN{ ($start,$end) = splice @ARGV, 1 }
print if $. == $start ... $. == $end' input.txt 2 5



John
--
use Perl;
program
fulfillment
.