[tpm] Fast(er) way of deleting X lines from start of a file

Tom Legrady legrady at gmail.com
Thu Oct 1 19:20:36 PDT 2009

Use the perl documentation installed on your machine with the binary.

     perldoc perlrun

describes all the command line options, including -p, -n, -i. You'll see the
file is processed line by line. Of course the system buffers are the
controlling factor for memory usager, if your lines are an ordinary length
of 80 or so characters, since the buffers are a few KB in size

On Thu, Oct 1, 2009 at 9:53 PM, Viktor Pavlenko <vvp at cogeco.ca> wrote:

> >>>>> "MK" == Madison Kelly <linux at alteeve.com> writes:
>    >> perl -i -ne 'print if $. > 20' file
>     MK> Where 'if' is the input file handle? I've not played with
>    MK> '$.'...
> $. is the line number, starting from 1. `if' is just an `if', you can
> write it traditional way: if ($. > 20) { print }. It says to print $_
> (omitted) if the line number is greater than 20. It's a perl
> one-liner, it allows you to read one line at a time and put it in $_,
> -n means don't print it, and -i tells perl to edit the file in place
> (all tmp file business is taken care of). What follows -e is the
> script to execute.
>    MK> 'If this works it'd be the pure-perl way I was hoping
>    MK> for. Do you know if this still reads the whole file into
>    MK> memory at once? My biggest concern, even more than speed, is
>    MK> that this may need to be done on files larger than available
>    MK> RAM.
> I'm sure it reads a line at a time and then throws it away, so no
> worries about memory. Your point about inefficiency of reading &
> copying remains valid.
> --
> Viktor
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20091001/678c0b44/attachment.html>

More information about the toronto-pm mailing list