#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    7
    Rep Power
    0

    Remove duplicate lines


    I'm using Emeditor, is there a macro or regex which removes duplicate lines, and replaces them with \n (new line). For example

    apples
    bananas
    carrots
    apples
    prunes
    bananas
    potatoes
    apples
    peach

    Result:

    apples
    bananas
    carrots

    prunes

    potatoes

    peach

    As you can see in the example, whatever was duplicated and got deleted, is now replaced with \n. Is there a regular expression for that, or a javascript macro? Thank you for your help.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    A regex, yes. As with all the answers so far you'll need to apply it repeatedly until it stops matching.
    Code:
    Replace ^(.*)$([\s\S]*?)^\1$ with \1\2

IMN logo majestic logo threadwatch logo seochat tools logo