develooper Front page | perl.beginners | Postings from April 2008

Re: Best way to grab lines n thru x of a file

Thread Previous | Thread Next
From:
John W. Krahn
Date:
April 10, 2008 10:36
Subject:
Re: Best way to grab lines n thru x of a file
Chas. Owens wrote:
> On Thu, Apr 10, 2008 at 12:24 PM, Jonathan Mast
> <jhmast.developer@gmail.com> wrote:
>> Hi, I have a ~125MB file of which I want to read lines n thru n+x and write
>>  those into a separate file.  What is the best way to go about this?
> 
> Use the flip-flop operator* (..):
> 
> perl -ne 'print if $. == 20 .. $. == 50' file

Which could be written simply as:

perl -ne 'print if 20 .. 50' file


John
-- 
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

Thread Previous | Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About