Re: delete last line



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

--
JP
.



Relevant Pages

  • 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)
  • Re: Al Franken is leaving...
    ... Bill O'Reilly, looking smug, announced during his Ridiculous ... Item segment, 11/17, Al Franken was leaving the " bankrupt ... Air America" but would probably show up on those far left ... This is Al's third trip to entertain the troops in the war ...
    (alt.fan.howard-stern)
  • Re: Al Franken is leaving...
    ... Bill O'Reilly, looking smug, announced during his Ridiculous ... Item segment, 11/17, Al Franken was leaving the " bankrupt ... Air America" but would probably show up on those far left ... This is Al's third trip to entertain the troops in the war ...
    (alt.fan.howard-stern)
  • Re: delete last line
    ... ex - filename <<DONE ... To delete 10 lines prior to the last line, leaving the last line: ... bill@xxxxxxxxxxxxx Bill Campbell; Celestial Software LLC ... "If taxation without consent is not robbery, ...
    (comp.unix.sco.misc)
  • Re: USA Today
    ... But if they added comics then I would have a reason not walk ... on their paper as I'm leaving my hotel room. ... on the bill that says you're being charged six bits or something ... it a point to request, and Every Single Time the clerkoid says ...
    (rec.arts.comics.strips)