Thanks Bego for the idea to collect the duplicate lines as additional info and for the information that IfFound and IfNotFound can also be used after a replace. That was new for me although I have written dozens of UltraEdit macros. Even an experienced user like I can learn from others. Thanks again.
I have modified the macro again. Now it also works for files with lines with UltraEdit style regular expression characters and it does not need a second macro as I first thought would be necessary. It now could be also converted to a macro with Unix style regular expressions instead of UltraEdit style. Only 5 simple regular expressions must be changed for Unix style.
The removing duplicate line replace command is now case-sensitive. Remove MatchCase
parameter if it should ignore case.
The collection of the duplicate lines is done now with clipboard 8, which improves execution speed a lot. The duplicate lines are sorted. If someone wants this macro without collecting the duplicate line info, remove the red
This macro is now added to my private collection of useful macros - see sticky forum topic Macro examples and reference for beginners and experts
which contains a macro file with the macros DelDupInfo+
(macro below) and DelDupInfo-
(macro below without the red lines).
The macro property Continue if a Find with Replace not found
or Continue if search string not found
must be checked for this macro.
Find RegExp "%^([~^p]^)"
Replace All "#MOFI_RULES#^1"Clipboard 8
Find RegExp "%#MOFI_RULES#*$"
Replace All ""IfFound
Find Up "#MOFI_RULES#"
Find RegExp "%#MOFI_RULES#*^p"
Key DOWN ARROW
Find RegExp "%#MOFI_RULES#"
Replace All ""NewFile
Find RegExp "%#MOFI_RULES#"
Replace All ""
"NO DUPLICATES :-)
SortAsc 1 -1 0 0 0 0 0 0
(v12+ of UE) at the end of the macro if you do not use UltraEdit style regular expressions by default - see search configuration. Macro command UnixReOff sets the regular expression option to UltraEdit style.Edit info:
Some comments added - see below!
This macro will not work for Unix files opened in Unix mode without conversion temporarily (on file load) or permanently to DOS before macro execution (^p matches CRLF!).
The macro is designed to remove duplicate lines only if a line matches another line 100%. If there are trailing spaces and the trailing spaces of 2 lines displayed identical do not match, the lines will not be removed and reported. Use the command TrimTrailingSpaces
at top of the macro after the command Top
, if you want to ignore trailing spaces and you can delete it.2007-11-01:
The macro has been rewritten completely because it damaged the file when there are soft-wrapped lines. The new macro works now also for a file with soft-wrapped lines. Also IfEof has been eliminated to let the macro work on Unicode files too, independent of the version of UltraEdit. IfEof works for Unicode files only since UE v13.20.