Re: delete last line



On Fri, Jan 11, 2008, Jean-Pierre Radley wrote:
Jeff Hyman typed (on Fri, Jan 11, 2008 at 11:20:40AM -0500):
| Jean-Pierre Radley typed (on Thu, Jan 10, 2008 at 05:55:06PM -0500):
| | pablo typed (on Thu, Jan 10, 2008 at 02:03:03PM -0800):
| | | how can I delete the last line of a text file from the command line ?
| | |
| | | I mean only last line
| |
| | sed '$d' in.file > out.file
| |
| | --
| | JP
|
| Well... now I'm curious.
|
| How would you delete ONLY the next-to-last line,
| leaving the previous very last line to replace
| the space where the next-to-last line was just
| removed?

Badly phrased question. If you remove a line, there is no "space left
behind". There would only be a "space left behind" if you deleted the
just the line's visible contents, AKA as blanking the line. When one
says remove, one means removing the 'newline' as well, so that there's
nothing left at all.

In any case, what you meant to do would want a small modification to what
Bill just posted:


ex - filename <<DONE
$
-
w
q
DONE

Or more easily:

ex - filename <<DONE
$-1d
w
q
DONE

To delete 10 lines prior to the last line, leaving the last line:

ex - filename <<DONE
$-11,$-1d
w
q
DONE

Bill
--
INTERNET: bill@xxxxxxxxxxxxx Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
FAX: (206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676

"If taxation without consent is not robbery, then any band of robbers
have only to declare themselves a government, and all their robberies
are legalized." -- Lysander Spooner, Letter to Grover Cleveland 1886
.



Relevant Pages

  • Re: Eric T Hu of Edison, NJ suspected of the 4 people slain in botched La. pool hall robbery
    ... leaving four people dead in a botched robbery. ... said Col. John Fortunato of the Jefferson Parish Sheriff's Office. ... the bar but ducked when the shooting began. ...
    (rec.sport.billiard)
  • Re: delete last line
    ... | On Fri, Jan 11, 2008, Jean-Pierre Radley wrote: ... |>Bill just posted: ... | ex - filename <<DONE ... | To delete 10 lines prior to the last line, leaving the last line: ...
    (comp.unix.sco.misc)
  • problem with regular expressions following code snippet...
    ... strip the end filename off and the 2 directories ... // retrieves URL of itself, then strips the directories only leaving ...
    (comp.lang.php)
  • Re: delete last line
    ... | leaving the previous very last line to replace ... says remove, one means removing the 'newline' as well, so that there's ... Bill just posted: ... ex - filename <<DONE ...
    (comp.unix.sco.misc)
  • Re: A Repeatable Crash in MS-Word
    ... > Why would I want to open a file while in the process of saving another? ... I've done it when I find that the filename I was about to Save As under ... Being able to open it, evaluate it, and close it again without leaving ... Prev by Date: ...
    (microsoft.public.mac.office.word)