perl

Perl file example - A program to extract lines from a file

After trying some other approaches, I finally create a Perl program to extract lines from the middle of a file. Just give it the line number to start at, and a second line number to stop at, and this Perl program will print all the lines from the file in that range.

The source code for this Perl program is shown below.

Sample usage:

extract.pl 500 1000 myBigFile > smallerFile

Here's the code for extract.pl:

A Perl extract program

Ever need a program to extract some lines from the middle of a file, say lines 50-500 of a 10,000 line file? Well, I did, so I wrote one in Perl. Here's the code for "extract.pl, which lets me extract lines from a file by specifying the firstLine and lastLine that I want printed from a file:

Tue, June 18, 2002

I'm still living in the Perl world, and that's a good thing. Did I mention that Perl rules for text processing?! Perl is the technology that enables "smart news", or whatever I choose to call it (other name candidates: filtered news, robonews, newsbot).

Mon, June 17, 2002

Perl continues to rule the world, at least the text-processing world. The latest example is HTML::TokeParser, which lets me easily extract HREF's from documents. With this much-improved document parser and the search engine set up, I hope some form of smartnews/robonews will be available soon.

Wed, June 5, 2002

Yesterday I was reminded of cetus-links. At last check they have over 18,000 links related to the OO world. While I'm in the linkmeister neighborhood, cgi-resources is still a decent reference for Perl programs.

A Perl reverse lines tip

Perl rules! Yesterday I needed a program that would print a file in reverse, i.e., last line first, first line last. Before I could fret "man, how am I going to do this?", a powerful two-line program spewed forth:

@lines = <>;
print reverse @lines;

Life is good.

Syndicate content