But that result is not exactly of what you want as for example line 2 and 3 are in wrong order.

What you want is really a very special sort and therefore not a simple sort. The sorting criterias are:

If string (number) after equal sign on current line is greater than the string (number) after equal sign on the line compared with, put the current line before the compared line.

If string (number) after equal sign on current line is smaller than the string (number) after equal sign on the line compared with, put the current line after the compared line.

If string (number) after equal sign on current line is equal the string (number) after equal sign on the line compared with, one more sort must be used.

If string (number) before equal sign on current line is greater than the string (number) before equal sign on the line compared with, put the current line after the compared line.

If string (number) before equal sign on current line is smaller than the string (number) before equal sign on the line compared with, put the current line before the compared line.

If string (number) before equal sign on current line is equal the string (number) before equal sign on the line compared with, do not change the sort order (duplicate line).

Such a sort is possible with a script and a custom sort function, but I do not yet have time to write it. Perhaps there is another forum user who has some time to write this little script for you.

Advanced sort options for descending sort of the lines depending on number after equal sign.

Best regards from an UC/UE/UES for Windows user from Austria

Here is the script which produces the result you want. It does the primary descending sort and the secondary ascending sort on lines with equal second number.

// Function DesAscSort sorts lines primary in descending order based on
// a number after the first equal sign. If two lines have the same number
// after the first equal sign, the lines are sorted secondary in ascending
// order according to the number before the first equal sign. Lines without
// an equal sign like the empty string at end of the array if file ends with
// a line termination are moved to end of the file with keeping their order.
/* Example:
11 = 487
13 = 484
There is no equal sign.
12 = 484
One more line without equal sign.
14 = 492
becomes
14 = 492
11 = 487
12 = 484
13 = 484
There is no equal sign.
One more line without equal sign.
*/
function DesAscSort (sLineA, sLineB)
{
var nEqualSignPosA = sLineA.indexOf('=');
var nEqualSignPosB = sLineB.indexOf('=');
// Does line A contain an equal sign?
if (nEqualSignPosA < 0)
{
// No! Does line B contain an equal sign?
if (nEqualSignPosB < 0)
{
return 0; // No, do not change order of the lines.
}
return 1; // Yes, put line A after line B.
}
// Yes, line A contains an equal sign.
// Does line B contain an equal sign?
if (nEqualSignPosB < 0)
{
return -1; // No, put line A before line B.
}
// Both lines contain an equal sign.
// It is expected that there is an integer number left the first equal
// sign and another integer number right the equal sign and the number
// of digits is constant on all lines. There is no check made if those
// conditions are met by all lines containing an equal sign.
// Get from both lines the number after the equal sign.
var sNumberA = sLineA.replace(/^.*?=[ \t]*(\d+).*$/,"$1");
var sNumberB = sLineB.replace(/^.*?=[ \t]*(\d+).*$/,"$1");
// Is the string (number) of line A greater the string (number) of
// line B, line A must be put before line B in the array (file).
if (sNumberA > sNumberB)
{
return -1;
}
// Is the string (number) of line B greater the string (number) of
// line A, line A must be put after line B in the array (file).
else if (sNumberA < sNumberB)
{
return 1;
}
// The numbers after the first equal sign are identical on both lines.
// Get from both lines the number left of the first equal sign.
sNumberA = sLineA.replace(/^(\d+).+$/,"$1");
sNumberB = sLineB.replace(/^(\d+).+$/,"$1");
// Is the string (number) of line A greater the string (number) of
// line B, line A must be put after line B in the array (file).
if (sNumberA > sNumberB)
{
return 1;
}
// Is the string (number) of line B greater the string (number) of
// line A, line A must be put before line B in the array (file).
else if (sNumberA < sNumberB)
{
return -1;
}
return 0; // Both numbers are identical, no change in order required.
}
if (UltraEdit.document.length > 0) // Is any file opened?
{
// Define environment for this script.
UltraEdit.insertMode();
UltraEdit.columnModeOff();
// Determine line terminator type (DOS/Windows or UNIX).
var sLineTerm = (UltraEdit.activeDocument.lineTerminator != 1) ? "\r\n" : "\n";
UltraEdit.activeDocument.selectAll();
if (UltraEdit.activeDocument.isSel()) // Is file not empty?
{
UltraEdit.selectClipboard(9);
UltraEdit.activeDocument.copy();
// Get the clipboard content into an array of strings
// with each string being a line in active file.
var asLines = UltraEdit.clipboardContent.split(sLineTerm);
// Sort the lines with the special sorting function.
asLines.sort(DesAscSort);
// Build the block in user clipboard 9 and paste it
// into the file overwriting the entire selection.
UltraEdit.clipboardContent = asLines.join(sLineTerm);
UltraEdit.activeDocument.paste();
// Clear user clipboard 9, select Windows clipboard and
// exit script with setting caret to top of the file.
UltraEdit.clearClipboard();
UltraEdit.selectClipboard(0);
UltraEdit.activeDocument.top();
}
}

Best regards from an UC/UE/UES for Windows user from Austria