Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!casbah.acns.nwu.edu!nucsrl!tellab5!vpnet!dattier From: dattier@vpnet.chi.il.us (David W. Tamkin) Newsgroups: comp.unix.questions Subject: Re: need help on unix Message-ID: <1991Jun11.161026.5034@vpnet.chi.il.us> Date: 11 Jun 91 16:10:26 GMT References: <1991Jun11.004109.21966@unixg.ubc.ca> Distribution: na Organization: VPnet Public Access Unix, Villa Park, Illinois 60181-2206 Lines: 35 wangf@unixg.ubc.ca (Frank Wang) wrote in <1991Jun11.004109.21966@unixg.ubc.ca>: | Does anyone out there know how to delete the first few lines or the last | few lines from a file without evoke a editor? The reason is the file is | too large to be edited. OK. Let's see. Do you know precisely how many lines you want to drop? If you want to get rid of the first eight lines (for example), tail +9 oldfile > newfile or sed '1,8d' oldfile > newfile To drop the last, say, ten lines isn't so easy. sed, for example (I'm sure all this can be done more elegantly in awk or perl), doesn't know when the last line is coming up until it receives EOF, so you cannot address line "$-10" in sed. If you can wc -l oldfile and see that it has, let us say, 50,000 lines, and you want to drop the last ten, then sed '49990q' oldfile > newfile will do it. If you don't know the precise number of lines to drop but are basing the point on the occurrence of an expression, the methods are generally adaptable, and when they aren't you can use grep -n to get a line number. The key, I think, is to use some utility that examines a file as a stream without trying to hold it all at once. David Tamkin PO Box 7002 Des Plaines IL 60018-7002 dattier@vpnet.chi.il.us GEnie:D.W.TAMKIN CIS:73720,1570 MCIMail:426-1818 708 518 6769 312 693 0591 "Parker Lewis Can't Lose" mailing list: flamingo-request@esd.sgi.com (reflector) flamingo-request@mcs.com (digest)