[TriLUG] Perl question. . .

Stephen Joyce stephen at physics.unc.edu
Tue Feb 17 21:33:14 EST 2009

On Tue, 17 Feb 2009, Justin Parker wrote:

> I'd like to read a file and pipe the text on a particular line to a new
> file.  Does anyone have a suggestion on how I could script this?

If it doesn't have to be perl, why not just use head and tail? To find X 
lines, starting at line Y:

tail -n +Y $filename | head -n X

So to save only the 1000th line, you might want to do something like:

tail -n +1000 /path/to/my/infile.txt | head -n 1 > /path/to/my/outfile.txt

Cheers, Stephen
Stephen Joyce
PANIC - Physics and Astronomy Network Infrastructure and Computing
University of North Carolina at Chapel Hill 
voice: 919.962.7214
fax: 919.962.0480

A cubicle is just a padded cell without a door.

More information about the TriLUG mailing list