Welcome to the IDM Forum. This forum is meant as a user-to-user support mechanism where users can share knowledge and tips for all IDM software.
Since these forums are user-to-user based, IDM does not regularly read or reply to the posts in this forum. For problem reports, suggestions, or feature requests, you must email us directly. Our trained technical support staff answers most inquiries within 30 minutes.

InsertMode
ColumnModeOff
HexOff
UltraEditReOn
Bottom
IfColNumGt 1
InsertLine
IfColNumGt 1
DeleteToStartofLine
EndIf
EndIf
Top
TrimTrailingSpaces
Find MatchCase RegExp "[ ^t]+"
Replace All "#"
Find MatchCase RegExp "%^([0-9]+^)$"
Replace All "#^1"
Find MatchCase RegExp "%^([0-9]+#^)"
Replace All "#^1"
Find MatchCase RegExp "^([0-9]^)#"
Replace All "^1^p#"
Loop 0
Find MatchCase "#"
IfNotFound
ExitLoop
EndIf
Key LEFT ARROW
StartSelect
Find MatchCase RegExp Select "%[~#^p]"
IfFound
Key LEFT ARROW
EndSelect
SortAsc Numeric 2 -1 0 0 0 0 0 0
Find MatchCase RegExp "%[0-9]"
IfNotFound
ExitLoop
EndIf
Else
SelectToBottom
SortAsc Numeric 2 -1 0 0 0 0 0 0
ExitLoop
EndIf
EndLoop
Top
Find MatchCase "#"
Replace All ""// Define the environment for the macro.
InsertMode
ColumnModeOff
HexOff
UltraEditReOn
// Make sure that also last line of file ends with a line termination.
Bottom
IfColNumGt 1
InsertLine
IfColNumGt 1
DeleteToStartofLine
EndIf
EndIf
// Back to top of the file and delete all trailing spaces.
Top
TrimTrailingSpaces
// Find strings with 1 or more spaces / tabs and replace
// each of them by character #.
Find MatchCase RegExp "[ ^t]+"
Replace All "#"
// Find lines containing only a number and nothing else
// and insert the character # at beginning of such lines.
Find MatchCase RegExp "%^([0-9]+^)$"
Replace All "#^1"
// Find lines starting with a number followed by character #
// and insert the character # at beginning of such lines.
Find MatchCase RegExp "%^([0-9]+#^)"
Replace All "#^1"
// Find a digit followed by character # and insert a line
// termination after the digit.
Find MatchCase RegExp "^([0-9]^)#"
Replace All "^1^p#"
// Now every number of a day is on a separate line with # at beginning.
// Run the following loop until the numbers of all days are sorted.
Loop 0
// Find next line with character # at beginning. If not found, exit loop.
Find MatchCase "#"
IfNotFound
ExitLoop
EndIf
// Move caret left to found character # and start selection mode.
Key LEFT ARROW
StartSelect
// Select everything up to a line not starting with character # (= next day).
Find MatchCase RegExp Select "%[~#^p]"
IfFound
// If such a line could be found, move the caret left to beginning of line
// while selection mode is still active. Now all number lines of a day are
// selected. Sort this block which results in discarding the selection and
// moving the caret to start of the first line of the block. So use another
// regular expression Find to move caret downwards to the first line of the
// next day (starts with a digit).
Key LEFT ARROW
EndSelect
SortAsc Numeric 2 -1 0 0 0 0 0 0
Find MatchCase RegExp "%[0-9]"
IfNotFound
ExitLoop
EndIf
Else
// If there is no line not starting with character # anymore, this is the
// last day in the file. Select from start of first line with a number to
// end of line and sort this last block before exiting the loop. This is
// the typical exit. The other 2 exits are just for security in case the
// macro is executed on a wrong file.
SelectToBottom
SortAsc Numeric 2 -1 0 0 0 0 0 0
ExitLoop
EndIf
EndLoop
// Move caret to top of file and delete all inserted # from the file.
Top
Find MatchCase "#"
Replace All ""
function Numsort (a, b) // Function for sorting the array of numbers.
{
return a - b;
}
if (UltraEdit.document.length > 0) // Is any file opened in UltraEdit.
{
// Define the environment for the script.
UltraEdit.insertMode();
UltraEdit.columnModeOff();
UltraEdit.activeDocument.hexOff();
UltraEdit.perlReOn();
// Make sure that also last line of file ends with a line termination.
UltraEdit.activeDocument.bottom();
if (UltraEdit.activeDocument.isColNumGt(1))
{
UltraEdit.activeDocument.insertLine();
if (UltraEdit.activeDocument.isColNumGt(1))
{
UltraEdit.activeDocument.deleteToStartOfLine();
}
}
UltraEdit.activeDocument.top(); // Move caret to top of the file.
// Define the parameters for a Perl regular expression search finding
// 1 or more lines containing only space or tab delimited integers.
UltraEdit.activeDocument.findReplace.mode=0;
UltraEdit.activeDocument.findReplace.matchCase=true;
UltraEdit.activeDocument.findReplace.matchWord=false;
UltraEdit.activeDocument.findReplace.regExp=true;
UltraEdit.activeDocument.findReplace.searchDown=true;
if (typeof(UltraEdit.activeDocument.findReplace.searchInColumn) == "boolean")
{
UltraEdit.activeDocument.findReplace.searchInColumn=false;
}
// Run the following loop as long as line(s) containing only
// integer numbers with or without spaces/tabs are found.
while (UltraEdit.activeDocument.findReplace.find("^(?:[ \\t\\d\\-]+\\r\\n)+"))
{
// The found lines are selected. Extract from the selected block
// all integer numbers into an array of strings with each element
// containing 1 number as string.
var asNumbers = UltraEdit.activeDocument.selection.match(/-*\d+/g);
// Create a second array of integers and convert the integer strings into
// real integers. The integer array is next sorted according to the values.
var nNumCount = asNumbers.length;
if (nNumCount > 1)
{
var anNumbers = new Array(nNumCount);
for (var nIndex = 0; nIndex < nNumCount; nIndex++)
{
anNumbers[nIndex] = parseInt(asNumbers[nIndex],10);
}
anNumbers.sort(Numsort);
// Create in memory a block with pairs of the found integers.
var sBlock = "";
for (var nFirst = 0; nFirst < (nNumCount - 1); nFirst++)
{
for (var nSecond = nFirst + 1; nSecond < nNumCount; nSecond++)
{
sBlock += anNumbers[nFirst].toString() + " " + anNumbers[nSecond].toString() + "\r\n";
}
}
// Write this block to the file overwritting the selection.
UltraEdit.activeDocument.write(sBlock);
}
}
} // Create in memory a block with pairs of the found integers.
var sBlock = "";
for (var nFirst = 0; nFirst < (nNumCount - 1); nFirst++)
{
for (var nSecond = nFirst + 1; nSecond < nNumCount; nSecond++)
{
sBlock += anNumbers[nFirst].toString() + " " + anNumbers[nSecond].toString() + "\r\n";
}
} // Create in memory a block with the sorted numbers.
var sBlock = "";
for (var nIndex = 0; nIndex < nNumCount; nIndex++)
{
sBlock += anNumbers[nIndex].toString() + "\r\n";
}




