I downloaded the script file findDupLines.js from UltraEdit macros and scripts download page.
Why are lines 13 and 14 displayed as "Duplicate"?
Why are lines 13 and 14 displayed as "Duplicate"?
UE 26.20.0.74 German / Win 10 x 64 Pro
Code: Select all
// This is a complex script which searches for duplicate lines.
// THE DUPLICATE CHECK IS CASE SENSITIVE!
// Change the following variable to 0 to disable case sensitivity.
var nCaseSensitive = 1;
if (UltraEdit.document.length > 0)
{
UltraEdit.insertMode();
if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
UltraEdit.activeDocument.top();
UltraEdit.ueReOn();
UltraEdit.activeDocument.findReplace.mode=0;
UltraEdit.activeDocument.findReplace.matchCase=false;
UltraEdit.activeDocument.findReplace.matchWord=false;
UltraEdit.activeDocument.findReplace.regExp=false;
UltraEdit.activeDocument.findReplace.searchDown=true;
if (typeof(UltraEdit.activeDocument.findReplace.searchInColumn) == "boolean")
{
UltraEdit.activeDocument.findReplace.searchInColumn=false;
}
UltraEdit.outputWindow.write("Beginning duplicate check...");
if (nCaseSensitive)
{
UltraEdit.activeDocument.findReplace.matchCase = true;
UltraEdit.outputWindow.write("Case sensitivity enabled");
}
else
{
UltraEdit.activeDocument.findReplace.matchCase = false;
UltraEdit.outputWindow.write("Case sensitivity disabled");
}
var nDuplicates = 0;
var nLineNumber = 1;
var nStartIndex = 0;
var anDuplicateLines = [];
var sFullFileName = UltraEdit.activeDocument.path;
while (!UltraEdit.activeDocument.isEof())
{
var nIndex = nStartIndex;
while(nIndex < anDuplicateLines.length)
{
if (anDuplicateLines[nIndex] > nLineNumber) break;
if (nLineNumber == anDuplicateLines[nIndex])
{
nStartIndex = nIndex + 1;
nIndex = -1;
break;
}
nIndex++;
}
if (nIndex >= 0)
{
UltraEdit.activeDocument.selectLine();
var sCurrentLine = UltraEdit.activeDocument.selection.replace(/[\r\n]+/g,"");
if (sCurrentLine.length)
{
var bFirstDuplicate = true;
var sFindLine = sCurrentLine.replace(/\^/g,"^^");
while (UltraEdit.activeDocument.findReplace.find(sFindLine))
{
UltraEdit.activeDocument.selectLine();
var sFoundLine = UltraEdit.activeDocument.selection.replace(/[\r\n]+/g,"");
if (sFoundLine.length == sCurrentLine.length)
{
var nDuplicateLine = UltraEdit.activeDocument.currentLineNum;
if (bFirstDuplicate)
{
UltraEdit.outputWindow.write("\n" + sFullFileName + "(" + nLineNumber + "): " + sCurrentLine);
bFirstDuplicate = false;
}
UltraEdit.outputWindow.write(sFullFileName + "(" + nDuplicateLine + "): " + sFoundLine);
for (nIndex = nStartIndex; nIndex < anDuplicateLines.length; nIndex++)
{
if (anDuplicateLines[nIndex] > nDuplicateLine) break;
}
anDuplicateLines.splice(nIndex,0,nDuplicateLine);
nDuplicates++;
}
}
}
}
nLineNumber++;
UltraEdit.activeDocument.gotoLine(nLineNumber,1);
if (UltraEdit.activeDocument.currentLineNum != nLineNumber) break;
}
UltraEdit.outputWindow.write("\nDuplicate check complete.");
UltraEdit.outputWindow.showWindow(true);
if (nDuplicates > 0)
{
UltraEdit.outputWindow.write(nDuplicates + " duplicate line" + ((nDuplicates > 1) ? "s" : "") + " found in this file.");
}
else
{
UltraEdit.outputWindow.write("No duplicate lines found in this file.");
}
}
Code: Select all
// This is a simple script which removes duplicate lines.
// THE DUPLICATE CHECK IS CASE SENSITIVE!
// Change the following variable to 0 to disable case sensitivity.
var nCaseSensitive = 1;
if (UltraEdit.document.length > 0)
{
UltraEdit.insertMode();
if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
UltraEdit.activeDocument.top();
UltraEdit.ueReOn();
UltraEdit.activeDocument.findReplace.mode=0;
UltraEdit.activeDocument.findReplace.matchCase=false;
UltraEdit.activeDocument.findReplace.matchWord=false;
UltraEdit.activeDocument.findReplace.regExp=false;
UltraEdit.activeDocument.findReplace.searchDown=true;
if (typeof(UltraEdit.activeDocument.findReplace.searchInColumn) == "boolean")
{
UltraEdit.activeDocument.findReplace.searchInColumn=false;
}
UltraEdit.outputWindow.write("Beginning duplicate removal...");
if (nCaseSensitive)
{
UltraEdit.activeDocument.findReplace.matchCase = true;
UltraEdit.outputWindow.write("Case sensitivity enabled");
}
else
{
UltraEdit.activeDocument.findReplace.matchCase = false;
UltraEdit.outputWindow.write("Case sensitivity disabled");
}
var nDuplicates = 0;
var nLineNumber = 1;
var sFullFileName = UltraEdit.activeDocument.path;
while (!UltraEdit.activeDocument.isEof())
{
UltraEdit.activeDocument.selectLine();
var sCurrentLine = UltraEdit.activeDocument.selection.replace(/[\r\n]+/g,"");
if (sCurrentLine.length)
{
var nLineDuplicates = 0;
var sFindLine = sCurrentLine.replace(/\^/g,"^^");
while (UltraEdit.activeDocument.findReplace.find(sFindLine))
{
UltraEdit.activeDocument.selectLine();
var sFoundLine = UltraEdit.activeDocument.selection.replace(/[\r\n]+/g,"");
if (sFoundLine.length == sCurrentLine.length)
{
UltraEdit.activeDocument.deleteText();
nLineDuplicates++;
nDuplicates++;
}
}
if (nLineDuplicates)
{
UltraEdit.outputWindow.write("\n" + sFullFileName + "(" + nLineNumber + "): " + sCurrentLine);
UltraEdit.outputWindow.write("Removed " + nLineDuplicates + " duplicate" + ((nLineDuplicates > 1) ? "s" : "") +
" of this line");
}
}
nLineNumber++;
UltraEdit.activeDocument.gotoLine(nLineNumber,1);
if (UltraEdit.activeDocument.currentLineNum != nLineNumber) break;
}
UltraEdit.outputWindow.write("\nDuplicate removal complete.");
UltraEdit.outputWindow.showWindow(true);
if (nDuplicates > 0)
{
UltraEdit.outputWindow.write(nDuplicates + " duplicate line" + ((nDuplicates > 1) ? "s" : "") + " removed from this file.");
}
else
{
UltraEdit.outputWindow.write("No duplicate lines found in this file.");
}
}