[Linux-disciples] Deleting the first N lines of a file

Stephen R Laniel steve at laniels.org
Thu Feb 9 11:27:55 EST 2006


On Wed, Feb 08, 2006 at 08:55:49PM -0500, Stephen R Laniel wrote:
> Does anyone know of a very fast way to delete the first N
> lines of a file? (That is, after the deletion, the file's
> size will reduce from N + k to k lines.) Speed is rather
> important here, so something like

I was thinking that maybe

NUMLINES=`some command involving grep`
head -n $NUMLINES filename > outfile.txt
sed -i "1,${NUMLINES}d" filename

would do the trick. But I'm playing with that now, on a
fairly representative very large file, and it seems to take
a very long time. Hm.

-- 
Stephen R. Laniel
steve at laniels.org
+(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.bostoncoop.net/pipermail/linux-disciples/attachments/20060209/241dbd11/attachment.pgp


More information about the Linux-disciples mailing list