• Login
Community
  • Login

Sort lines but keep the hierarchy

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
5 Posts 3 Posters 462 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.
  • R
    Rune Egenes
    last edited by May 15, 2023, 7:57 AM

    Hi,

    I hope someone can help me with this. I’m looking for a way for this:

    People
    –>Man
    –>Woman
    –>Child
    Sports
    –> Football
    –>Tennis
    –>Golf

    To sort and become like this:

    Sports
    –> Football
    –>Tennis
    –>Golf
    People
    –>Man
    –>Woman
    –>Child

    Thank you.

    1 Reply Last reply Reply Quote 0
    • G
      guy038
      last edited by guy038 May 15, 2023, 8:52 AM May 15, 2023, 8:43 AM

      Hello, @rune-egenes and All,

      Well, not difficult to achieve with regular expressions !


      So we start with this INPUT text :

      People
      –>Man
      –>Woman
      –>Child
      Sports
      –> Football
      –>Tennis
      –>Golf
      
      • Firstly, perform the following regex S/R, with displays all header strings in consecutive lines :

        • SEARCH \R(?=\x{2013}>)

        • REPLACE Leave EMPTY

      And we get the temporary text, below :

      People–>Man–>Woman–>Child
      Sports–> Football–>Tennis–>Golf
      
      • Secondly, run the option Edit > Line Operations > Sort Lines Lexicographically Descending

      After the sort operation, we get :

      Sports–> Football–>Tennis–>Golf
      People–>Man–>Woman–>Child
      
      • Thirdly, execute this last regex S/R, below :

        • SEARCH (?=\x{2013}>)

        • REPLACE \r\n    or    \n if you deal with UNIX files

      And, here is your expected OUTPUT text :

      Sports
      –> Football
      –>Tennis
      –>Golf
      People
      –>Man
      –>Woman
      –>Child
      

      Best Regards

      guy038

      R 1 Reply Last reply May 15, 2023, 9:08 AM Reply Quote 3
      • R
        Rune Egenes @guy038
        last edited by May 15, 2023, 9:08 AM

        @guy038 Thank you so much. I also have some lists that need to be sorted where
        -> is tab (\t) is there a regex for that? Thank you

        1 Reply Last reply Reply Quote 0
        • G
          guy038
          last edited by May 15, 2023, 9:24 AM

          Hi, @rune-egenes and All,

          Easy !

          • First regex :

            • SEARCH \R(?=\t)

            • REPLACE Leave EMPTY

          • Sort

          • Second regex

            • SEARCH (?=\t)

            • REPLACE \r\n    or    \n if you deal with UNIX files

          BR

          guy038

          1 Reply Last reply Reply Quote 1
          • T Terry R referenced this topic on Jul 26, 2023, 8:04 PM
          • M
            Mr. Jaims
            last edited by Aug 28, 2023, 3:47 PM

            This post is deleted!
            1 Reply Last reply Reply Quote -1
            2 out of 5
            • First post
              2/5
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors