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

Madison Kelly linux at alteeve.com
Thu Oct 1 08:47:38 PDT 2009

G. Matthew Rice wrote:
> On Wed, 2009-09-30 at 11:39 -0400, Madison Kelly wrote: 
>> Thus far, I've opened a file, read it in, shifted/ignored the first X 
>> number of line and then wrote out the resulting file. This works, but 
>> strikes me as horribly inefficient. Doubly so when the file could be 
>> larger than RAM.
>>    So then, is there a more efficient/faster way of saying "Delete the 
>> first X number of lines from file foo"?
> Do you have to do it in Perl?  You could do:
>     tail -n +N <in.txt >out.txt
> where: N = X + 1
> Regards, 
> --matt

I would much rather do it in perl. The module set this method is in is 
designed to be a pure-perl module. However, if the other methods don't 
work, it's another option to experiment with. As I mentioned to Antonio 
though, if yours or his methods shows a significant performance 
increase, I make make one of these two methods an optional way of 
pruning the file for people who know their program will be on a system 
with sed/tail.



More information about the toronto-pm mailing list