EmEditor (text editor) Forum Index
   Regular Expressions
     how to delete duplicate lines
Register To Post

Flat Previous Topic | Next Topic
Poster Thread
Yutaka
Posted on: 9/29/2006 11:56 am
Webmaster
Joined: 9/28/2006
From: Redmond
Posts: 2399
Re: how to delete duplicate lines
It isn't easy to do with regular expressions, but how about a macro like this (JavaScript):


// Create an array
a = new Array();

// Fill the array a with all lines (with returns) in the document.
document.selection.StartOfDocument();
for( ; ; ){
    y = document.selection.GetActivePointY( eePosLogical );
    document.selection.SelectLine();
    sLine = document.selection.Text;
    if( sLine == "" ) {   // Reached the end of document, escape from the loop
        break;
    }
    a.push( sLine );
    document.selection.Collapse();
    if( document.selection.GetActivePointY( eePosLogical ) == y ) {
        // Reached the end of document (the last line without return), escape from the loop
        break;
    }
}

// Delete duplicate elements.
for( i = 0; i < a.length; i++ ){
    sLine = a[i];
    for( j = i + 1; j < a.length; j++ ){
        if( sLine == a[j] ){
            a.splice( j, 1 );
            j--;
        }
    }
}

// Replace the entire document with new elements
document.selection.SelectAll();
document.selection.Text = a.join( "" );


Please let me know if you have questions.


----------------
Yutaka Emura
Developer of EmEditor
http://www.emeditor.com/

Flat Previous Topic | Next Topic


Subject Poster Date
   how to delete duplicate lines user 9/29/2006 7:27 am
   » Re: how to delete duplicate lines Yutaka 9/29/2006 11:56 am
       Re: how to delete duplicate lines user 9/29/2006 12:42 pm
       Re: how to delete duplicate lines Hellados 4/18/2009 1:10 am
         Re: how to delete duplicate lines Yutaka 4/18/2009 1:26 pm
           Re: how to delete duplicate lines Salabim 1/3/2010 10:33 am
             Re: how to delete duplicate lines Yutaka 1/4/2010 9:51 pm
               Re: how to delete duplicate lines Salabim 1/5/2010 11:07 pm
       Re: how to delete duplicate lines Deipotent 8/10/2011 12:21 pm
         Re: how to delete duplicate lines Yutaka 8/10/2011 1:11 pm
           Re: how to delete duplicate lines Deipotent 8/10/2011 3:50 pm
             Re: how to delete duplicate lines Yutaka 8/10/2011 4:37 pm
     Re: how to delete duplicate lines Monkeyman 6/5/2011 12:47 pm
       Re: how to delete duplicate lines raikrivera 7/28/2011 1:36 am

Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文