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

Madison Kelly linux at alteeve.com
Thu Oct 1 08:42:14 PDT 2009


Viktor Pavlenko wrote:
>>>>>> "AS" == Antonio Sun <antoniosun at lavabit.com> writes:
> 
>     AS> [...]
> 
>     AS> If using shell script instead of Perl is an option, then  sed is the best
>     AS> tool
> 
>     AS>   ToDel=20
>     AS>   sed -i "1,${ToDel}d" file
> 
>     AS> will delete the first 20 lines from the file.
> 
> perl -i -ne 'print if $. > 20' file
> 
> (my two cents in Perl)

Where 'if' is the input file handle? I've not played with '$.'... If 
this works it'd be the pure-perl way I was hoping for. Do you know if 
this still reads the whole file into memory at once? My biggest concern, 
even more than speed, is that this may need to be done on files larger 
than available RAM.

Thanks!

Madi



More information about the toronto-pm mailing list