editing / marking / highlighting of duplicate lines

Help with writing and playing macros

editing / marking / highlighting of duplicate lines

Postby Peter » Tue Apr 14, 2009 4:04 am

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
User avatar
Peter
Basic User
Basic User
 
Posts: 33
Joined: Mon Nov 01, 2004 12:00 am
Location: Switzerland

Re: marking / highlighting of duplicate lines

Postby pietzcker » Tue Apr 14, 2009 4:22 am

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
User avatar
pietzcker
Master
Master
 
Posts: 241
Joined: Sun Aug 22, 2004 11:00 pm

Re: marking / highlighting of duplicate lines

Postby Peter » Tue Apr 14, 2009 4:39 am

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
User avatar
Peter
Basic User
Basic User
 
Posts: 33
Joined: Mon Nov 01, 2004 12:00 am
Location: Switzerland

Re: editing / marking / highlighting of duplicate lines

Postby pietzcker » Tue Apr 14, 2009 8:40 am

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...
User avatar
pietzcker
Master
Master
 
Posts: 241
Joined: Sun Aug 22, 2004 11:00 pm

Re: editing / marking / highlighting of duplicate lines

Postby pietzcker » Tue Apr 14, 2009 9:09 am

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
User avatar
pietzcker
Master
Master
 
Posts: 241
Joined: Sun Aug 22, 2004 11:00 pm

Re: editing / marking / highlighting of duplicate lines

Postby Peter » Thu Apr 16, 2009 4:08 pm

Hello pietzcker

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

Thanks

Peter
User avatar
Peter
Basic User
Basic User
 
Posts: 33
Joined: Mon Nov 01, 2004 12:00 am
Location: Switzerland

Re: editing / marking / highlighting of duplicate lines

Postby Peter » Mon May 11, 2009 9:42 am

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
User avatar
Peter
Basic User
Basic User
 
Posts: 33
Joined: Mon Nov 01, 2004 12:00 am
Location: Switzerland


Return to Macros