Remove all lines except two duplicates ones

Remove all lines except two duplicates ones

8

    Nov 18, 2007#1

    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:

    236
    MasterMaster
    236

      Nov 19, 2007#2

      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...

      8

        Nov 20, 2007#3

        Any help to either pietzker or me? :oops:

        6,675585
        Grand MasterGrand Master
        6,675585

          Nov 20, 2007#4

          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 ""
          Best regards from an UC/UE/UES for Windows user from Austria

          8

            Nov 21, 2007#5

            WORKS!

            BUT: The macro continues to run EVEN after finishing. PLEASE help! :oops:

            6,675585
            Grand MasterGrand Master
            6,675585

              Nov 21, 2007#6

              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.
              Best regards from an UC/UE/UES for Windows user from Austria