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

Antonio Sun antoniosun at lavabit.com
Wed Sep 30 10:03:45 PDT 2009

On Wed, Sep 30, 2009 at 11:57 AM, Alex Beamish <talexb at gmail.com> wrote:

> >  So then, is there a more efficient/faster way of saying "Delete the
> first X
> > number of lines from file foo"?
> I would expect you could fashion something workable like this
>  #  Get the number of lines in the file ..
>  wc -l file
>  #  tail the desired number of lines to a new file ..
>  tail -n $numberOfLinesInFile-$numberOfLinesYouDontWant file >newfile
>  #  and move the files around.
>  rm file; mv newfile file

If using shell script instead of Perl is an option, then  sed is the best

  sed -i "1,${ToDel}d" file

will delete the first 20 lines from the file.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20090930/897e2d37/attachment-0001.html>

More information about the toronto-pm mailing list