Community
    • Login

    Sort Lines Lexicographically did not work

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    61 Posts 20 Posters 22.0k 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.
    • guy038G
      guy038
      last edited by guy038

      Hello, @terry-r,

      Terry, your image is… comforting !

      What a concentrate of technology for the time and what apparent robustness !

      A simple look at the machine’s feet shows that it was made to last and seemed to be built with common sense !

      Not like this modern concept of programmed obsolescence :-(

      Also, good restoration, deserved for this wonderful object ;-))

      Best Regards,

      guy038

      P.S. : It was my quarter of an hour of nostalgia ;-))

      1 Reply Last reply Reply Quote 1
      • Alan KilbornA
        Alan Kilborn @guy038
        last edited by

        @guy038 said in Sort Lines Lexicographically did not work:

        Folllowing the Alan’s idea of a Ctrl + V operation,

        I think you read what I said wrongly.

        Ctrl+v does NOT do anything to line-endings in the remainder of the file.
        It will, however, convert line-endings on the lines that are being pasted.

        It is the Edit menu’s Paste command that does it to the ENTIRE file.
        There doesn’t even have to be a line-ending in what you are pasting; it can be a simple as a single character in the clipboard, e.g. an a, and the entire-file line-ending conversion takes place upon (menu-invoked) Paste.

        This is amazing, because from this you’d think they are one and the same:

        3c9aa7ce-d15b-4dda-bbac-fc23886cd738-image.png

        But they are not equivalent. Give it a try!!

        1 Reply Last reply Reply Quote 0
        • guy038G
          guy038
          last edited by guy038

          Hi, @alan-kilborn,

          I still don’t fully understand your last post !

          Do you mean that using the Edit > Paste menu option OR the Ctrl + V shortcut do not produce the same results ?

          With my old XP SP3 laptop, ( for still few days ! ) it seems identical !?

          To my mind :

          • After the Ctrl + C operation, lines, placed in the clipboard, still contain their initial different line-endings

          • After the Ctrl + V operation, the clipboard replaces the current selection with its contents, using the current line-ending, defined in the status bar

          BR

          guy038

          Alan KilbornA 1 Reply Last reply Reply Quote 0
          • Alan KilbornA
            Alan Kilborn @guy038
            last edited by Alan Kilborn

            @guy038

            I still don’t fully understand your last post !
            Do you mean that using the Edit > Paste menu option OR the Ctrl + V shortcut do not produce the same results ?

            That’s EXACTLY what I’m saying.

            Take some mixed line-ending data:

            47b49269-0bfe-44cb-aff4-d9e4257b1621-image.png

            Copy (make selection, then press Ctrl+c) some lines, say these, to the clipboard:

            c5ac0801-ef68-4379-ba89-f0863a18c15c-image.png

            Move caret to start of file and Ctrl+v paste them:

            d1fc8c05-efe3-4854-9a23-1712306fac98-image.png

            Note that although in the copy the 3 lines had a CRLF, a LF and a CR line-ending, respectively (see the blue section in the screenshot), as the new first 3 lines of the file (created by the Ctrl+v paste) they all have been given CRLF line-endings.

            Now, move back to start of file and paste again, this time using the Edit menu’s Paste entry, to obtain:

            270fd7a6-02e5-4586-929b-e52fbd95d709-image.png

            Note that all lines of the file have now been converted to CRLF type line endings, which matches my line-ending type indicated in the status bar:

            f075f510-bc62-4f57-87cc-c9574f7d70dd-image.png

            Is it only me that this happens for??

            I’m using 7.9.3, Win10

            1 Reply Last reply Reply Quote 2
            • Terry RT
              Terry R
              last edited by Terry R

              @Alan-Kilborn said in Sort Lines Lexicographically did not work:

              Is it only me that this happens for??

              Nope, happens for me too. And I can say I’ve haven’t messed with my configs much either so I’d say that’s a built-in feature out of the box.

              In my case I too had the Windows (CR LF) setting in bottom bar. I had 4 lines, CR/LF, then LF, then CR followed by another CR/LF. After paste they all became the CR/LF.

              d5c9ba47-36fd-4109-90c3-eb4a883c37f0-image.png

              Edit: should say this was done with the Ctrl-C and Ctrl-V hotkeys

              Terry

              1 Reply Last reply Reply Quote 1
              • gstaviG
                gstavi
                last edited by

                Copy-paste is very intuitive but, as advanced users should know, pretty complicated by definition. That why some applications have the paste special function.
                Copy is taking a selected entity and creates multiple representations of it in the clipboard.
                Paste selects the most fitting representation and adds it into the destination, possibly also converting it on the fly.
                Paste special allows the user to select the relevant representation from the clipboard rather than use the application’s default.

                The text copying behavior described above is ideal for most Notepad++ users. Copied text is adjusted to the document properties, encoding and line endings.

                Most people when copying text from UTF-8 unix style ending into UCS-2-LE windows style ending would want the text converted both to the proper encoding and to the selected line ending to keep the destination file consistent.

                You could ask for Notepad++ to have paste special function with “paste maintaining line endings” option but which user would want it?

                Alan KilbornA 1 Reply Last reply Reply Quote 0
                • guy038G
                  guy038
                  last edited by guy038

                  Hi, @alan-kilborn, @terry-r, @gstavi, @mathlete2 and All,

                  Many thanks, Alan for your informative post ! I have not noticed this fact, yet, although I’m using N++ daily, since 12 years about !

                  Of course, I just did the simple test : Ctrl + A - ctrl + C - Ctrl + V which , anyway, can be used to uniform all line-endings to the ending-line value of the status bar !

                  I confirm , that I get the same behavior with Win XP SP3, too !


                  So, in summary, we can say that :

                  • A Ctrl + V operation paste the clipboard’s contents, using the current line-ending definition, in status bar, for each line pasted, only

                  • A Edit > Paste operation paste the clipboard’s contents AND change all line-endings, of current file, by the current line-ending definition, in status bar

                  Best Regards,

                  guy038

                  P.S. : How did you find out that particularity, Alan ?

                  Alan KilbornA 1 Reply Last reply Reply Quote 0
                  • Alan KilbornA
                    Alan Kilborn @guy038
                    last edited by

                    @guy038 said in Sort Lines Lexicographically did not work:

                    How did you find out that particularity, Alan ?

                    Best that I can recall:

                    I think it came from experimenting with data after seeing a thread such as this one, where someone is complaining that sorting doesn’t work.

                    I turned visible line-endings on (which I do not normally do because it is so overwhelming), and I wrote a script to randomize line endings in the active tab.

                    And then I started looking at the sorting problem.

                    At some point along the journey, I did a Paste using the right-click context menu (must have been, because I would never paste from the Edit menu – too much effort) and noticed the entire-file conversion effect.

                    Then, a bit more experimenting to find that Edit menu paste is same as context menu, but Ctrl+v paste is different.

                    Somehow I forgot to mention it before yesterday, which is unusual for me, but sometimes, like all of us, I get distracted. :-)

                    1 Reply Last reply Reply Quote 2
                    • Alan KilbornA
                      Alan Kilborn @gstavi
                      last edited by

                      @gstavi

                      Most of what you’ve said I agree with.
                      But, I don’t think that a paste operation should manipulate data that is outside of the range of what is being pasted.

                      Say I have a huge file and I paste something (a line or 2) into it.
                      Now perhaps I have to wait noticeable time while Notepad++ adjusts all the line-endings in my file.
                      This is perhaps unreasonable.

                      Or say I am intentionally wanting to maintain mixed line endings in a file.
                      Not a use-case for me, but I’ve seen users wanting this.
                      So okay, what I paste in is subject to eol conversion, but meanwhile so is everything else.

                      So luckily, users using a menu-based Paste are probably in the minority – most use Ctrl+v, which doesn’t have strange behavior in this regard.

                      gstaviG 1 Reply Last reply Reply Quote 3
                      • gstaviG
                        gstavi @Alan Kilborn
                        last edited by

                        @Alan-Kilborn said

                        But, I don’t think that a paste operation should manipulate data that is outside of the range of what is being pasted.

                        I agree. I didn’t read the entire previous post carefully enough.
                        The behavior of the menu paste should be classified as a bug. The ctrl-c, ctrl-v is behaving as it should.

                        1 Reply Last reply Reply Quote 2
                        • mplungjanM
                          mplungjan @guy038
                          last edited by

                          @guy038 This is the only thing that worked for me. What a pain

                          Alan KilbornA 1 Reply Last reply Reply Quote 0
                          • Alan KilbornA
                            Alan Kilborn @mplungjan
                            last edited by

                            @mplungjan said in Sort Lines Lexicographically did not work:

                            This is the only thing that worked for me. What a pain

                            What is the only thing that worked for you?
                            And what is a “pain”?

                            I presume you mean having to deal with inconsistent line-endings in your file before being able to sort the lines?

                            Perhaps you should be happy that Notepad++ refusing to sort the lines correctly has alerted you to the fact that your file is technically corrupted?

                            P 1 Reply Last reply Reply Quote 1
                            • P
                              Peter Vazny @Alan Kilborn
                              last edited by

                              @alan-kilborn said in Sort Lines Lexicographically did not work:

                              Perhaps you should be happy that Notepad++ refusing to sort the lines correctly has alerted you to the fact that your file is technically corrupted?

                              I am grateful for the product, but from a UI perspective, this is definitely an inconsistent behavior between what is displayed and what sort expects. If Notepad++ treats the different line endings the same for display, it should also treat them the same for sorting. At the minimum it should display a warning that the reason it did not perform a sort is due to line ending inconsistencies.

                              For the record all my line endings were LF, but because it was an unsaved new document that defaulted to EOL Convention -> Windows (CR LF), the sort was not working. I had to search for the problem and read through this thread to figure out what was wrong. Which seems a long way around to working out a problem with something that should be intuitive.

                              Alan KilbornA 1 Reply Last reply Reply Quote 2
                              • Alan KilbornA
                                Alan Kilborn @Peter Vazny
                                last edited by

                                @peter-vazny

                                The real problem is that the editing component, Scintilla, while it supports the notion of a line-ending type for a file, it does not enforce that (sadly). If it did that, the downstream feature in Notepad++, in this case sorting, would work correctly. Sure, Notepad++ developers could compensate for that, but for whatever reason, have chosen not to.

                                Alan KilbornA 1 Reply Last reply Reply Quote 1
                                • Alan KilbornA
                                  Alan Kilborn @Alan Kilborn
                                  last edited by

                                  @alan-kilborn said in Sort Lines Lexicographically did not work:

                                  Notepad++ developers could compensate for that, but for whatever reason, have chosen not to.

                                  And this looks like the official tracking item for what hasn’t been done: https://github.com/notepad-plus-plus/notepad-plus-plus/issues/7735

                                  1 Reply Last reply Reply Quote 1
                                  • Terry RT Terry R referenced this topic on
                                  • Terry RT Terry R referenced this topic on
                                  • Jeffrey EdisonJ
                                    Jeffrey Edison
                                    last edited by

                                    Here was the problem that I had. Notepad++ was setup with Windows style line endings (CR LF: \r\n), but the file contained Unix style line endings (LF: \n), so while it appeared to have correct line endings, it did not according to Windows style line endings. Thus the sort did nothing.
                                    Solution: cut and paste into a new file so that the LF became CR LF.

                                    1 Reply Last reply Reply Quote 0
                                    • C
                                      Cooeeeee
                                      last edited by

                                      I’ll drop a comment here because Google brought me here.

                                      I’ve been using Notepad++ for years. My most used feature is Sort Lexicographically to sort a column mode selection (i.e. I essentially have a table of data). For example, I’ll use Alt+Shift and maybe select columns 27-30 across all lines, then do a lexicographical sort on that.

                                      Today I encountered a list that wasn’t sorting correctly. I’ve not had this problem before. My lines had some tabs prior to the columns I was trying to sort. Reading through this thread gave me the idea to try the “TAB to space” conversion. My listed would sort correctly after making that adjustment. Somehow the tabs were breaking it. I figured I’ll leave this tip here in case it can help anyone else.

                                      It breaks again if I use the Space To Tab (All) option.

                                      The spaces / tabs are not part of the column I’m trying to sort - they are outside my selection.

                                      Alan KilbornA CoisesC 2 Replies Last reply Reply Quote 0
                                      • Alan KilbornA
                                        Alan Kilborn @Cooeeeee
                                        last edited by

                                        @Cooeeeee said in Sort Lines Lexicographically did not work:

                                        My lines

                                        Might have been more helpful if you had shown the data that illustrates your failure…

                                        1 Reply Last reply Reply Quote 0
                                        • Rui ChenR
                                          Rui Chen
                                          last edited by

                                          Here is a very simple strange case:

                                          > sort file1
                                          end of line
                                          first line, all spaces in the file
                                          { key = ‘7’, a},
                                          { key = ‘7 Pro’, a},

                                          > sort file2
                                          end of line
                                          first line, all spaces in the file
                                          { key = ‘7 Pro’, v},
                                          { key = ‘7’, v},

                                          Only difference is that “a” vs “v” in those two lines.

                                          PeterJonesP 1 Reply Last reply Reply Quote 0
                                          • PeterJonesP
                                            PeterJones @Rui Chen
                                            last edited by

                                            @Rui-Chen ,

                                            Sorry, I cannot replicate. You either didn’t do a good job of explaining the data and sequence you took, or you did something wrong when trying to do your sort.

                                            If I have two nearly-identical data sets, which only differ in a vs v in the location you described, the two files sort identically using Edit > Line Operations > Sort Lines Lexicographically Ascending

                                            file “a”, before sort

                                            1
                                            { key = '7 Pro', a},
                                            2
                                            { key = '7', a},
                                            3
                                            

                                            file “a” after sort

                                            1
                                            2
                                            3
                                            { key = '7 Pro', a},
                                            { key = '7', a},
                                            

                                            file “v” before sort

                                            1
                                            { key = '7 Pro', v},
                                            2
                                            { key = '7', v},
                                            3
                                            

                                            file “v” after sort

                                            1
                                            2
                                            3
                                            { key = '7 Pro', v},
                                            { key = '7', v},
                                            

                                            There is no difference between those results, and they work as expected.

                                            You might want to check if you have different line endings in the different files, or if one file has mixed line endings and the other doesn’t, or something. (View > Show Symbol > Show All Characters or Show End of Line). You can embed a screenshot with the line-endings shown if you think it will help us replicate your problem.

                                            Please make use of the </> button in the toolbar to mark up example text, and make the example text actually replicate the problem. Also, share ?-menu’s Debug Info so we know what version, environment, and plugins you have, which might be influencing things.

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