Results 1 to 7 of 7

Thread: Sed: remove all but last consecutive matching line?

Threaded View

  1. #1
    Join Date
    Oct 2006
    Location
    Slovakia
    Beans
    590
    Distro
    Xubuntu 11.10 Oneiric Ocelot

    Sed: remove all but last consecutive matching line?

    Hello,

    I've got this problem: Whenever two or more lines matching "@@@@@" occur consecutively, I would like to remove all but the last one. Example file:

    Code:
    @@@@@ One
    Another line
    
    @@@@@ One
    @@@@@ Two
    @@@@@ Three
    @@@@@ Four
    Yet another line
    Desired outcome:

    Code:
    @@@@@ One
    Another line
    
    @@@@@ Four
    Yet another line
    I'd like to solve this in sed. Thanks very much in advance for any suggestion!
    Last edited by mahy; April 11th, 2011 at 08:58 AM. Reason: more precise example
    בראשית ברא אלהים את השמים ואת הארץ׃

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •