Monday, February 2, 2009

jEdit delete duplicate lines

In jEdit's Search and Replace dialog, select "Regular Expressions",  then Search for:
^(.\*)$\n\1

replace with:
$1

This tells jEdit to

  • start at the beginning of a line ^

  • find any characters, spaces, etc .*

  • up to the end of the line $

  • including a carriage return \n

  • that matches the text on the following line \1

  • then replace it with just the first matched line $1


The result is any lines that are duplicated will be replaced with just a single copy of the line.

1 comment:

  1. Cool! :)
    I just had to remove "\" before "*", so my pattern changed to ^(.*)$\n\1 . Looks like a typo or maybe some tool's initiative... :)

    And in case duplicates are there in more than one copy, it is possible to match an arbitrary number of them with the following pattern: ^(.*)$(?:\n\1)+

    ReplyDelete

Note: Only a member of this blog may post a comment.