Community
    • Login

    Sort lines but keep the hierarchy

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 3 Posters 905 Views 1 Watching
    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.
    • Rune EgenesR Offline
      Rune Egenes
      last edited by

      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
      • guy038G Offline
        guy038
        last edited by guy038

        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

        Rune EgenesR 1 Reply Last reply Reply Quote 3
        • Rune EgenesR Offline
          Rune Egenes @guy038
          last edited by

          @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
          • guy038G Offline
            guy038
            last edited by

            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
            • Terry RT Terry R referenced this topic on
            • Mr. JaimsM Offline
              Mr. Jaims
              last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote -1

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors