editing / marking / highlighting of duplicate lines

editing / marking / highlighting of duplicate lines

1581
Power UserPower User
1581

    Apr 14, 2009#1

    Hello

    I have lines like this

    Code: Select all

    a
    b
    c
    d
    d
    e
    f
    g
    g
    h
    and I want to find and select/highlight/edit the duplicate lines like this

    Code: Select all

    a
    b
    c
    d
       d
    e
    f
    g
       g
    h
    How to make it?

    Thanks

    Peter
    UE 26.20.0.74 German / Win 10 x 64 Pro

    236
    MasterMaster
    236

      Re: marking / highlighting of duplicate lines

      Apr 14, 2009#2

      Hi,

      to make sure I understand correctly:

      Can there also be more than two identical lines in a row (i.e, triplicates or more)?
      Do you want to add a couple of space characters in front of the duplicate(s), or what exactly do you want to do?

      Just finding and highlighting them is trivial (Perl regular expression ^(.*)(\r\n\1)+$), but if you want to modify them, I need more info.

      If you want to delete duplicates, just use the above regex in a Perl regex replace action, using \1 as the replace text.

      This only works with consecutive duplicates, not if you have something like

      a
      b
      b
      c
      b
      c
      d

      Cheers,
      Tim

      1581
      Power UserPower User
      1581

        Re: marking / highlighting of duplicate lines

        Apr 14, 2009#3

        Hello Tim

        thanks.

        - yes, also more than two identical lines are possible (triples, ...)
        - the most important aim is to "mark the lines durable", that means "add 10 spaces before them". Highlight is nie, but not prior.
        - yes, the lines are well sorted
        - no, deleting is not necessary.

        Peter
        UE 26.20.0.74 German / Win 10 x 64 Pro

        236
        MasterMaster
        236

          Apr 14, 2009#4

          Hm. Not as easy as I first thought.

          The easy part is finding the duplicate lines and adding 10 spaces in front of them. This can be done with the following macro:

          Code: Select all

          InsertMode
          ColumnModeOn
          HexOff
          Top
          PerlReOn
          Loop 0
          Find RegExp "^(.*\r\n)\1+"
          IfNotFound
          ExitLoop
          EndIf
          Key SHIFT
          Key UP ARROW
          "          "
          Key END
          EndLoop
          ColumnModeOff
          However, this will also indent the first line of each "block". Maybe someone has a better idea?

          I first tried fooling around with the hide/unhide selected lines feature - which worked fine in an interactive session (mark the block, indent it, hide it, then delete the indentation characters, then move the cursor down one line and unhide the hidden lines). This only deleted the indentation in the first line of the block. However, when I tried to do that in a macro, it would do all sorts of strange things. So I guess hiding/unhiding lines is not completely macro-safe...

            Apr 14, 2009#5

            I've found a solution (I think). Run the following macro after the previous one has done its job. It is important that the macro property "Continue if search string not found" (or similar, don't know the exact wording of the English version) is UNchecked for this macro (and checked for the other one, therefore you need two macros. I think. Somebody please prove me wrong).

            Code: Select all

            InsertMode
            ColumnModeOff
            HexOff
            Top
            PerlReOn
            Loop 0
            Find RegExp "^ {10}(.*\r\n)((?: {10}\1)+)"
            Replace "\1\2"
            IfNotFound
            ExitLoop
            EndIf
            Key UP ARROW
            EndLoop

            1581
            Power UserPower User
            1581

              Apr 16, 2009#6

              Hello pietzcker

              I will test it next week - for the next days I am not in the office..

              Thanks

              Peter

                May 11, 2009#7

                pietzcker wrote:Hm. Not as easy as I first thought.

                The easy part is finding the duplicate lines and adding 10 spaces in front of them. This can be done with the following macro:
                ...
                Hello pietzcker

                thanks a lot. This works fine for me and it is no problem that the first line is also indented.

                Have a nice week.

                Peter
                UE 26.20.0.74 German / Win 10 x 64 Pro