Remove all lines except two duplicates ones

Help with writing and playing macros

Remove all lines except two duplicates ones

Postby UltraEditLover » Sat Nov 17, 2007 10:35 pm

Suppose:

The lines in a file are:

0x0011D300
0x0013CE00
0x0015C900
0x0017C400
0x0017C400

0x0019BF00
0x001BBA00
0x001FB000
0x001FB000

0x0021AB00
0x0023A600

After running the macro the result should be: [only duplicates left]

0x0017C400
0x0017C400
0x001FB000
0x001FB000



Thanks. And It only has to check for duplicates, not triplicates. :P
As always post "fastest possible version" plz.

Could this be modified to something else to achieve the same result?
^(.*\r\n)\1+ :twisted:
User avatar
UltraEditLover
Newbie
 
Posts: 8
Joined: Tue Nov 13, 2007 12:00 am

Re: Remove all lines except two duplicates ones

Postby pietzcker » Sun Nov 18, 2007 7:23 pm

Hm. The following regex should do it (selects a line that is not preceded or followed by the same line), but UE says that it's an invalid regex.

Code: Select all
^(.*)\r\n(?<!\1\r\n\1\r\n)(?!\1)

Perl doesn't mind, so I don't know why UE does. It seems not to like the backreference in the negative lookbehind. Maybe someone has a better idea because I guess a pure regex would fit the bill as the fastest possible solution...
User avatar
pietzcker
Master
Master
 
Posts: 241
Joined: Sun Aug 22, 2004 11:00 pm

Re: Remove all lines except two duplicates ones

Postby UltraEditLover » Mon Nov 19, 2007 7:56 pm

Any help to either pietzker or me? :oops:
User avatar
UltraEditLover
Newbie
 
Posts: 8
Joined: Tue Nov 13, 2007 12:00 am

Re: Remove all lines except two duplicates ones

Postby Mofi » Tue Nov 20, 2007 8:22 am

Using the regular expression Tim has posted at Special Case: Remove Duplicates TOTALLY, not just one following macro should do the job.

It uses the same regular expression used before to delete all duplicates, but instead of deletion it marks the duplicate lines with a # at start of the lines. Then lines not starting with # are deleted and last the # character from start of the remaining lines are deleted. The result is what you want and it is very fast.

InsertMode
ColumnModeOff
HexOff
PerlReOn
Top
Find RegExp "^(.*)\r\n\1\r\n"
Replace All "#\1\r\n#\1\r\n"
Find RegExp "^[^#].*\r\n"
Replace All ""
Find RegExp "^#"
Replace All ""
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4054
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Remove all lines except two duplicates ones

Postby UltraEditLover » Tue Nov 20, 2007 9:58 pm

WORKS!

BUT: The macro continues to run EVEN after finishing. PLEASE help! :oops:
User avatar
UltraEditLover
Newbie
 
Posts: 8
Joined: Tue Nov 13, 2007 12:00 am

Re: Remove all lines except two duplicates ones

Postby Mofi » Wed Nov 21, 2007 8:12 am

The macro must stop after third replace all. Except you run it via Macro - Play Any/Multiple Times and have checked Play macro to End of File. That is wrong. The macro runs 3 replaces all from top of the file. There is no need for an external loop. Run it 1 times without the end of file option.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4054
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros