• Login
Community
  • Login

Operation of Sorting "Sort Lines as Decimals"

Scheduled Pinned Locked Moved General Discussion
7 Posts 3 Posters 601 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T
    Tim G
    last edited by Nov 29, 2024, 5:14 PM

    I’m using NPP 8.7.1 on Windows. I tried to sort a list of lines starting with IPv4 addresses using the Sort Lines as Decimals function in the Edit menu.

    That sorts on the first and second octet, but leaves the 3rd and 4th octet unsorted.

    I tried the lexical sort, which was closer, but of course sorted like this:

    172.16.0.12 
    172.16.0.127
    172.16.0.15 
    172.16.0.18 
    172.16.0.186
    172.16.0.19 
    172.16.0.20 
    172.16.0.212
    

    In a future update, could the decimal sort be modified to handle three decimals to properly sort ipv4, treating all octets as integers? Or is there a plug-in that does that?

    A 1 Reply Last reply Nov 29, 2024, 5:42 PM Reply Quote 0
    • A
      Alan Kilborn @Tim G
      last edited by Alan Kilborn Nov 29, 2024, 5:45 PM Nov 29, 2024, 5:42 PM

      @Tim-G said in Operation of Sorting "Sort Lines as Decimals":

      In a future update, could the decimal sort be modified to handle three decimals to properly sort ipv4, treating all octets as integers?

      Not very likely, but you need to check the FAQ from this site to see how to put in a feature request that the developers would see.

      I think you might be able to do it by:

      • regex replacement to expand all octets to be exactly 3 digits long (i.e., add leading zeroes to octets that are one or two digits long)
      • sort all lines decimal ascending
      • create a zero-width block selection right after the second . in each line
      • sort all lines decimal ascending again
      • regex replacement to remove any extra leading zeroes of each octet
      1 Reply Last reply Reply Quote 1
      • G
        guy038
        last edited by guy038 Nov 29, 2024, 7:44 PM Nov 29, 2024, 7:35 PM

        Hello, @tim-g, @alan-kilborn and All,

        @tim-g, I do not understand, because, personally, if I use your INPUT test, below :

        172.16.0.12 
        172.16.0.127
        172.16.0.15 
        172.16.0.18 
        172.16.0.186
        172.16.0.19 
        172.16.0.20 
        172.16.0.212
        

        And I run the Edit > Line Operations > Sort Lines As Integers Ascending, I do get the expected OUTPUT text, below :

        172.16.0.12 
        172.16.0.15 
        172.16.0.18 
        172.16.0.19 
        172.16.0.20 
        172.16.0.127
        172.16.0.186
        172.16.0.212
        

        My Debug Info :

        Notepad++ v8.7.2 (64-bit)
        Build time : Nov 25 2024 - 18:27:38
        Path : D:\872_x64\notepad++.exe
        Command Line :
        Admin mode : OFF
        Local Conf mode : ON
        Cloud Config : OFF
        Periodic Backup : OFF
        OS Name : Windows 10 Pro (64-bit)
        OS Version : 22H2
        OS Build : 19045.5131
        Current ANSI codepage : 1252
        Plugins :
        mimeTools (3.1)
        NppConverter (4.6)
        NppExport (0.4)
        ComparePlus (1.2)

        Best Regards,

        guy038

        A 1 Reply Last reply Nov 29, 2024, 8:01 PM Reply Quote 1
        • A
          Alan Kilborn @guy038
          last edited by Nov 29, 2024, 8:01 PM

          @guy038 said in Operation of Sorting "Sort Lines as Decimals":

          Edit > Line Operations > Sort Lines As Integers Ascending, I do get the expected OUTPUT text

          Now, that’s interesting, and I wouldn’t have expected it. :-)

          1 Reply Last reply Reply Quote 1
          • A
            Alan Kilborn
            last edited by Alan Kilborn Nov 30, 2024, 1:19 PM Nov 30, 2024, 11:48 AM

            So after some further investigation (i.e., looking at the code), it appears there is a lot of logic behind Notepad++'s integer sorting. You’d think it would simply refuse to sort if it sees non-integer data for the sort “key”, but this is not the case, obviously.

            As another example, I would have expected “bad things” from trying to sort (integer, ascending) the following:

            zzz8440
            zzz20
            zzz21482
            zzz852
            zzz917
            zzz1038
            zzz14
            zzz243
            zzz258
            zzz1166
            

            but it actually produces:

            zzz14
            zzz20
            zzz243
            zzz258
            zzz852
            zzz917
            zzz1038
            zzz1166
            zzz8440
            zzz21482
            

            On the other hand, attempting to sort (integer, ascending):

            zzz 1038
            zzz 8440
            zzz   14
            zzz  917
            zzz  258
            zzz21482
            zzz  243
            zzz   20
            zzz 1166
            zzz  852
            

            doesn’t really produce happy results:

            zzz21482
            zzz 1038
            zzz 1166
            zzz 8440
            zzz  243
            zzz  258
            zzz  852
            zzz  917
            zzz   14
            zzz   20
            

            I understand why it does what it does (after examining the code and thinking about it), but as a user of the software maybe I don’t want to do too much thinking (just…wanna…sort).

            And, it seems like if the software is going to “help me out” by ignoring e.g. the zzz text, maybe an integer sort could also ignore any leading spaces on integer data.

            It doesn’t really affect me one way or another, because I would do my sorting of numerical data without any surrounding non-numerical data, and then move it into place with other text.

            The user manual is silent on the nuances of such sorting, stating only As Integers means that 10 will sort as being bigger than 2.

            So I guess OP on this thread “lucks out” in that @guy038 's sorting tip for IP4 data works.

            1 Reply Last reply Reply Quote 2
            • G
              guy038
              last edited by guy038 Nov 30, 2024, 10:19 PM Nov 30, 2024, 3:48 PM

              Hi, @tim-g, @alan-kilborn and All,

              Alan, I did some other tests regarding the Edit > Line Operations > Sort Lines As Integers Ascending option and, seemingly, any number of the list must be aligned on the left side in order that the sort is coherent !

              For example, the three following sorts are correct :

              zzz8440                           zzz14
              zzz20                             zzz20
              zzz21482                          zzz243
              zzz852                            zzz258
              zzz917            =>              zzz852
              zzz1038                           zzz917
              zzz14                             zzz1038
              zzz243                            zzz1166
              zzz258                            zzz8440
              zzz1166                           zzz21482
              
              zzz 8440                          zzz 14
              zzz 20                            zzz 20
              zzz 21482                         zzz 243
              zzz 852                           zzz 258
              zzz 917           =>              zzz 852
              zzz 1038                          zzz 917
              zzz 14                            zzz 1038
              zzz 243                           zzz 1166
              zzz 258                           zzz 8440
              zzz 1166                          zzz 21482
              
              zzz abc 8440                      zzz abc 14
              zzz abc 20                        zzz abc 20
              zzz abc 21482                     zzz abc 243
              zzz abc 852                       zzz abc 258
              zzz abc 917       =>              zzz abc 852
              zzz abc 1038                      zzz abc 917
              zzz abc 14                        zzz abc 1038
              zzz abc 243                       zzz abc 1166
              zzz abc 258                       zzz abc 8440
              zzz abc 1166                      zzz abc 21482
              

              Whereas the next two sorts are wrong, because the numbers are aligned on the right :

              zzz 8440                          zzz21482
              zzz   20                          zzz 1038
              zzz21482                          zzz 1166
              zzz  852                          zzz 8440
              zzz  917          ??              zzz  243
              zzz 1038                          zzz  258
              zzz   14                          zzz  852
              zzz  243                          zzz  917
              zzz  258                          zzz   14
              zzz 1166                          zzz   20
              
              zzz  8440                         zzz 21482
              zzz    20                         zzz  1038
              zzz 21482                         zzz  1166
              zzz   852                         zzz  8440
              zzz   917         ??              zzz   243
              zzz  1038                         zzz   258
              zzz    14                         zzz   852
              zzz   243                         zzz   917
              zzz   258                         zzz    14
              zzz  1166                         zzz    20
              

              Now, look this last sort, which is correct even when the first number, between two consecutive lines, are equal but not the second number ;-))

              zzz 8440  abc 778913              zzz 14    abc 325
              zzz 20    abc 1985                zzz 20    abc 468
              zzz 20    abc 468                 zzz 20    abc 1985
              zzz 917   abc 9568                zzz 243   abc 8784
              zzz 21482 abcd 51                 zzz 258   abc 1571
              zzz 8440  abc 9854                zzz 852   abc 695
              zzz 852   abc 695                 zzz 917   abc 0
              zzz 917   abc 0         =>        zzz 917   abc 9568
              zzz 1166  abc 357                 zzz 1038  abc 320
              zzz 1038  abc 320                 zzz 1166  abc 8
              zzz 14    abc 325                 zzz 1166  abc 357
              zzz 243   abc 8784                zzz 8440  abc 9854
              zzz 258   abc 1571                zzz 8440  abc 778913
              zzz 1166  abc 8                   zzz 21482 abcd 51
              zzz 21482 abcd 12345              zzz 21482 abcd 12345
              

              However, if the column of letters does not have the same length for all the records, all text, located after the first number correctly sorted, uses the default sort, whatever this column of letters is justified on the left or right side or the next column or numbers is aligned on the left side :

              zzz 8440  abc 778913              zzz 14     bc 325
              zzz 20    abc 1985                zzz 20     bc 468
              zzz 20     bc 468                 zzz 20    abc 1985
              zzz 917   abc 9568                zzz 243   abc 8784
              zzz 21482 abcd 51                 zzz 258     c 1571
              zzz 8440    c 9854                zzz 852   abc 695
              zzz 852   abc 695                 zzz 917   abc 9568
              zzz 917 abcde 0          ??       zzz 917 abcde 0
              zzz 1166      357                 zzz 1038  abc 320
              zzz 1038  abc 320                 zzz 1166      357
              zzz 14     bc 325                 zzz 1166  abc 8
              zzz 243   abc 8784                zzz 8440    c 9854
              zzz 258     c 1571                zzz 8440  abc 778913
              zzz 1166  abc 8                   zzz 21482 abcd 51
              zzz 21482 abcd 12345              zzz 21482 abcd 12345
              
              zzz 8440 abc 778913               zzz 14 bc 325
              zzz 20 abc 1985                   zzz 20 abc 1985
              zzz 20 bc 468                     zzz 20 bc 468
              zzz 917 abc 9568                  zzz 243 abc 8784
              zzz 21482 abcd 51                 zzz 258 c 1571
              zzz 8440 c 9854                   zzz 852 abc 695
              zzz 852 abc 695          ??       zzz 917 abc 9568
              zzz 917 abcde 0                   zzz 917 abcde 0
              zzz 1166   357                    zzz 1038 abc 320
              zzz 1038 abc 320                  zzz 1166   357
              zzz 14 bc 325                     zzz 1166 abc 8
              zzz 243 abc 8784                  zzz 8440 abc 778913
              zzz 258 c 1571                    zzz 8440 c 9854
              zzz 1166 abc 8                    zzz 21482 abcd 51
              zzz 21482 abcd 12345              zzz 21482 abcd 12345
              
              zzz 8440 abc  778913              zzz 14 bc     325
              zzz 20 abc    1985                zzz 20 abc    1985
              zzz 20 bc     468                 zzz 20 bc     468
              zzz 917 abc   9568                zzz 243 abc   8784
              zzz 21482 abcd 51                 zzz 258 c     1571
              zzz 8440 c    9854                zzz 852 abc   695
              zzz 852 abc   695                 zzz 917 abc   9568
              zzz 917 abcde 0        ??         zzz 917 abcde 0
              zzz 1166      357                 zzz 1038 abc  320
              zzz 1038 abc  320                 zzz 1166      357
              zzz 14 bc     325                 zzz 1166 abc  8
              zzz 243 abc   8784                zzz 8440 abc  778913
              zzz 258 c     1571                zzz 8440 c    9854
              zzz 1166 abc  8                   zzz 21482 abcd 51
              zzz 21482 abcd 12345              zzz 21482 abcd 12345
              

              Note also that, when two records have a first identical number and the next column of letters is of the same length too, the subsequent numbers seems to be sorted numerically, again ! This is the case of the last two sorted records, of the last four lists above, as 51 is obviously inferior to 12345

              zzz 21482 abcd 51
              zzz 21482 abcd 12345
              

              Best Regards,

              guy038

              A 1 Reply Last reply Nov 30, 2024, 3:52 PM Reply Quote 0
              • A
                Alan Kilborn @guy038
                last edited by Nov 30, 2024, 3:52 PM

                @guy038

                Peter should document all of this in the user manual.
                (Just kidding, Peter!)

                1 Reply Last reply Reply Quote 2
                6 out of 7
                • First post
                  6/7
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors