Re: delete last line



Bill Campbell typed (on Fri, Jan 11, 2008 at 09:47:37AM -0800):
| 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

I just replied to JP... and your reply here is the answer I was
curious about. Bill... you are the man!
JP, please disregard my last statement. I really don't
like you "that" much. <g>
- Jeff H
.



Relevant Pages

  • 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: 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: OT - Intelligent Design
    ... I'll be leaving on or about 13 Sep, and will then be gone on a 4-5 ... > week Epiphany Quest. ... quit selling Red Dogs. ...
    (rec.outdoors.rv-travel)