Loading ...
Sorry, an error occurred while loading the content.

RE: [Clip] Sorting groups?

Expand Messages
  • Art Kocsis
    Two possibilities: 1 - (A mod of yours): Replace all ^P with || (unique EOL char string) Replace all ] with ]^P (one line per
    Message 1 of 9 , Sep 4, 2011
    • 0 Attachment
      Two possibilities:
      1 - (A mod of yours):
      Replace all "^P" with "||" (unique EOL char string)
      Replace all "]" with "]^P" (one line per group)
      Select all
      Sort
      Replace all "||" with "^P"
      Replace all "[" with "[^P"

      2 - (Using arrays) - On 2nd thought this is too complicated
      Set delimiter to "]"
      Input doc/file to array
      Sort array
      Output to file

      Art


      At 09/04/2011 12:01, you wrote:
      >I figured out an inelegant method to do this. For anyone that's
      >interested, here's what I did.
      >1. Copy the first line in each group up to the opening bracket.
      >2. Replace all CR's between groups with double vertical bars, certain to
      >not otherwise exist in my files.
      >
      >So, each line becomes this:
      >[firstline||firstline again||rest||of||the||lines]
      >Sort ascending.
      >Replace all || with CR
      >Delete whatever follows [(a copy of firstline)
      >
      >Works good, but not pretty.
      >
      >Regards,
      >John
      >
      >
      >-----Original Message-----
      >From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On
      >Behalf Of John Shotsky
      >Sent: Sunday, September 04, 2011 09:28
      >To: ntb-clips@yahoogroups.com
      >Subject: [Clip] Sorting groups?
      >
      >I'd like to be able to sort groups alphabetically, ascending only. The
      >groups are identified with square brackets, and I
      >want to sort only on the first line in each group, with the other lines in
      >each group left in place.
      >
      >Here are two example groups: (Sort only on the first word in each group.)
      >
      >[
      >This should be the last group
      >A lot of lines may exist within this group and they should not be changed.
      >More lines.
      >More lines.
      >End of first group
      >]
      >[
      >Beginning of second group, which should become the first group
      >Lots more lines may exist in this group, and they should not be changed.
      >More lines.
      >More lines.
      >End of second group.
      >]
      >
      >I've played around with a few ideas, but so far I'm not even close. There
      >may be hundreds of such groups.
      >
      >Any ideas?
      >Thanks,
      >John
    • John Shotsky
      Thanks Art, that is an improvement, and I incorporated it. Regards, John From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of Art
      Message 2 of 9 , Sep 5, 2011
      • 0 Attachment
        Thanks Art, that is an improvement, and I incorporated it.

        Regards,
        John

        From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of Art Kocsis
        Sent: Sunday, September 04, 2011 17:53
        To: NoteTab-Clips
        Subject: RE: [Clip] Sorting groups?


        Two possibilities:
        1 - (A mod of yours):
        Replace all "^P" with "||" (unique EOL char string)
        Replace all "]" with "]^P" (one line per group)
        Select all
        Sort
        Replace all "||" with "^P"
        Replace all "[" with "[^P"

        2 - (Using arrays) - On 2nd thought this is too complicated
        Set delimiter to "]"
        Input doc/file to array
        Sort array
        Output to file

        Art

        At 09/04/2011 12:01, you wrote:
        >I figured out an inelegant method to do this. For anyone that's
        >interested, here's what I did.
        >1. Copy the first line in each group up to the opening bracket.
        >2. Replace all CR's between groups with double vertical bars, certain to
        >not otherwise exist in my files.
        >
        >So, each line becomes this:
        >[firstline||firstline again||rest||of||the||lines]
        >Sort ascending.
        >Replace all || with CR
        >Delete whatever follows [(a copy of firstline)
        >
        >Works good, but not pretty.
        >
        >Regards,
        >John
        >
        >
        >-----Original Message-----
        >From: ntb-clips@yahoogroups.com <mailto:ntb-clips%40yahoogroups.com> [mailto:ntb-clips@yahoogroups.com
        <mailto:ntb-clips%40yahoogroups.com> ] On
        >Behalf Of John Shotsky
        >Sent: Sunday, September 04, 2011 09:28
        >To: ntb-clips@yahoogroups.com <mailto:ntb-clips%40yahoogroups.com>
        >Subject: [Clip] Sorting groups?
        >
        >I'd like to be able to sort groups alphabetically, ascending only. The
        >groups are identified with square brackets, and I
        >want to sort only on the first line in each group, with the other lines in
        >each group left in place.
        >
        >Here are two example groups: (Sort only on the first word in each group.)
        >
        >[
        >This should be the last group
        >A lot of lines may exist within this group and they should not be changed.
        >More lines.
        >More lines.
        >End of first group
        >]
        >[
        >Beginning of second group, which should become the first group
        >Lots more lines may exist in this group, and they should not be changed.
        >More lines.
        >More lines.
        >End of second group.
        >]
        >
        >I've played around with a few ideas, but so far I'm not even close. There
        >may be hundreds of such groups.
        >
        >Any ideas?
        >Thanks,
        >John



        [Non-text portions of this message have been removed]
      • flo.gehrke
        ... Art (and John), I m trying to learn from that advice by I can t figure out how this could work. Could you give me a helping hand please? Regarding John s
        Message 3 of 9 , Sep 5, 2011
        • 0 Attachment
          --- In ntb-clips@yahoogroups.com, Art Kocsis <artkns@...> wrote:
          >
          > 1 - (A mod of yours):
          > Replace all "^P" with "||" (unique EOL char string)
          > Replace all "]" with "]^P" (one line per group)
          > Select all
          > Sort
          > Replace all "||" with "^P"
          > Replace all "[" with "[^P"


          Art (and John),

          I'm trying to learn from that advice by I can't figure out how this could work. Could you give me a helping hand please?

          Regarding John's problem (message #22045), he is dealing with a structure like...

          [
          DDD group.
          More lines.
          More lines.
          End of DDD group
          ]
          [
          CCC group.
          More lines.
          More lines.
          End of CCC group
          ]
          [
          BBB group.
          More lines.
          More lines.
          End of BBB group.
          ]
          [
          AAA group.
          More lines.
          More lines.
          End of AAA group.
          ]

          I tried to translate your advice into the following clip...

          ^!Jump 1
          ^!Replace "^P" >> "||" WAS
          ^!Replace "]" >> "]^P" WAS
          ^!Toolbar Sort Ascending
          ^!Replace "||" >> "^P" WAS
          ^!Replace "[" >> "[^P" WAS


          When running this clip against that structure, for me, the result is...


          [

          DDD group.
          More lines.
          More lines.
          End of DDD group
          ]

          [

          AAA group.
          More lines.
          More lines.
          End of AAA group.
          ]

          [

          BBB group.
          More lines.
          More lines.
          End of BBB group.
          ]

          [

          CCC group.
          More lines.
          More lines.
          End of CCC group
          ]


          Obviously, this doesn't accord with John's intentions. What am I misunderstanding here?

          Thanks,
          Flo


          P.S. In Nov 2008, Art presented another clip that was dealing with a quite similar problem (see message #18724). On basis of that proposal, I wrote the following clip. Adapting it to John's topic, it could like this...

          ^!SetScreenUpdate Off
          ; Remove brackets
          ^!Replace "\[|\](\R|\Z)" >> "" WARS
          ; Insert a pipe before each CRNL
          ^!Replace "^P" >> "|^P" WAS
          ; Remove pipe at beginning of empty lines / save empty line as
          ; delimiter between blocks
          ^!Replace "^\|$" >> "" WARS
          ^!Select All
          ^!Toolbar Join Lines
          ; Remove empty lines / prevent them from getting moved to document
          ; start by sorting
          ^!Replace "^P^P" >> "^P" WAS
          ^!Menu Modify/Lines/Sort/Ascending
          ; Insert closing/opening bracket between blocks
          ^!Replace "^P" >> "^P]^P[^P" WAS
          ; Replace pipe plus space with CRNL / no space between blocks after pipe
          ^!Replace "\|\x20|\|\R" >> "\r\n" WARS
          ; Insert opening bracket at document start
          ^!Replace "\A" >> "[\r\n" WRS
          ; Remove opening bracket at document end
          ^!Replace "\R\[\R\Z" >> "" RS

          When applied to the above-mentioned structure, I get a perfect sorting...

          [
          AAA group.
          More lines.
          More lines.
          End of AAA group.
          ]
          [
          BBB group.
          More lines.
          More lines.
          End of BBB group.
          ]
          [
          CCC group.
          More lines.
          More lines.
          End of CCC group
          ]
          [
          DDD group.
          More lines.
          More lines.
          End of DDD group
          ]

          Maybe I completely misunderstood the whole job... 8-(
        • John Shotsky
          You didn t misunderstand, your solution does work, but it is actually more complex than the one I settled on. In mine, I just replaced all CRLF with ||, and
          Message 4 of 9 , Sep 5, 2011
          • 0 Attachment
            You didn't misunderstand, your solution does work, but it is actually more complex than the one I settled on.
            In mine, I just replaced all CRLF with ||, and then added back a CRLF after each ]. That gives one line per section with
            || as delimiters between the original lines. In your example, you would have just 4 lines.

            If you insert a GoTo Exit before Select all, you should see one line per section, starting with [ and ending with ]. It
            even preserves blank lines, as intended.
            Then you just sort those lines and replace the || with CRLF, and add a CRLF after [.

            Mine has other things that I need to manage besides these sections, so I renamed them with [AAA, [AAAA, [AAAAA in front
            of them, and a ] after them, so they would bubble to the top in the sort. At the end, those tags are removed, and the
            original strings remain, in the proper order. (Those are header lines that are simply treated as additional sections to
            sort.)

            Regards,
            John

            From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of flo.gehrke
            Sent: Monday, September 05, 2011 10:03
            To: ntb-clips@yahoogroups.com
            Subject: Re: [Clip] Sorting groups?


            --- In ntb-clips@yahoogroups.com <mailto:ntb-clips%40yahoogroups.com> , Art Kocsis <artkns@...> wrote:
            >
            > 1 - (A mod of yours):
            > Replace all "^P" with "||" (unique EOL char string)
            > Replace all "]" with "]^P" (one line per group)
            > Select all
            > Sort
            > Replace all "||" with "^P"
            > Replace all "[" with "[^P"

            Art (and John),

            I'm trying to learn from that advice by I can't figure out how this could work. Could you give me a helping hand please?

            Regarding John's problem (message #22045), he is dealing with a structure like...

            [
            DDD group.
            More lines.
            More lines.
            End of DDD group
            ]
            [
            CCC group.
            More lines.
            More lines.
            End of CCC group
            ]
            [
            BBB group.
            More lines.
            More lines.
            End of BBB group.
            ]
            [
            AAA group.
            More lines.
            More lines.
            End of AAA group.
            ]

            I tried to translate your advice into the following clip...

            ^!Jump 1
            ^!Replace "^P" >> "||" WAS
            ^!Replace "]" >> "]^P" WAS
            ^!Toolbar Sort Ascending
            ^!Replace "||" >> "^P" WAS
            ^!Replace "[" >> "[^P" WAS

            When running this clip against that structure, for me, the result is...

            [

            DDD group.
            More lines.
            More lines.
            End of DDD group
            ]

            [

            AAA group.
            More lines.
            More lines.
            End of AAA group.
            ]

            [

            BBB group.
            More lines.
            More lines.
            End of BBB group.
            ]

            [

            CCC group.
            More lines.
            More lines.
            End of CCC group
            ]

            Obviously, this doesn't accord with John's intentions. What am I misunderstanding here?

            Thanks,
            Flo

            P.S. In Nov 2008, Art presented another clip that was dealing with a quite similar problem (see message #18724). On
            basis of that proposal, I wrote the following clip. Adapting it to John's topic, it could like this...

            ^!SetScreenUpdate Off
            ; Remove brackets
            ^!Replace "\[|\](\R|\Z)" >> "" WARS
            ; Insert a pipe before each CRNL
            ^!Replace "^P" >> "|^P" WAS
            ; Remove pipe at beginning of empty lines / save empty line as
            ; delimiter between blocks
            ^!Replace "^\|$" >> "" WARS
            ^!Select All
            ^!Toolbar Join Lines
            ; Remove empty lines / prevent them from getting moved to document
            ; start by sorting
            ^!Replace "^P^P" >> "^P" WAS
            ^!Menu Modify/Lines/Sort/Ascending
            ; Insert closing/opening bracket between blocks
            ^!Replace "^P" >> "^P]^P[^P" WAS
            ; Replace pipe plus space with CRNL / no space between blocks after pipe
            ^!Replace "\|\x20|\|\R" >> "\r\n" WARS
            ; Insert opening bracket at document start
            ^!Replace "\A" >> "[\r\n" WRS
            ; Remove opening bracket at document end
            ^!Replace "\R\[\R\Z" >> "" RS

            When applied to the above-mentioned structure, I get a perfect sorting...

            [
            AAA group.
            More lines.
            More lines.
            End of AAA group.
            ]
            [
            BBB group.
            More lines.
            More lines.
            End of BBB group.
            ]
            [
            CCC group.
            More lines.
            More lines.
            End of CCC group
            ]
            [
            DDD group.
            More lines.
            More lines.
            End of DDD group
            ]

            Maybe I completely misunderstood the whole job... 8-(



            [Non-text portions of this message have been removed]
          • flo.gehrke
            ... Thanks John! I can t confirm this, though your remarks correspond exactly with the clip I made following Art s advice. The result is still the mess I
            Message 5 of 9 , Sep 5, 2011
            • 0 Attachment
              --- In ntb-clips@yahoogroups.com, "John Shotsky" <jshotsky@...> wrote:
              >
              > You didn't misunderstand, your solution does work, but it
              > is actually more complex than the one I settled on.
              > In mine, I just replaced all CRLF with ||, and then added back
              > a CRLF after each ]. That gives one line per section with
              > || as delimiters between the original lines. In your example,
              > you would have just 4 lines.
              >
              > If you insert a GoTo Exit before Select all, you should see one
              > line per section, starting with [ and ending with ]. It
              > even preserves blank lines, as intended.
              > Then you just sort those lines and replace the || with CRLF,
              > and add a CRLF after [.

              Thanks John!

              I can't confirm this, though your remarks correspond exactly with the clip I made following Art's advice. The result is still the mess I described.

              The only explanation I have for this is that, probably, the original data structure you posted with message #22045 isn't valid any more.

              For example: After...

              ^!Replace "^P" >> "||" WAS
              ^!Replace "]" >> "]^P" WAS

              the result is...

              [||DDD group.||More lines.||More lines.||End of DDD group||]
              ||[||CCC group.||More lines.||More lines.||End of CCC group||]
              ||[||BBB group.||More lines.||More lines.||End of BBB group.||]
              ||[||AAA group.||More lines.||More lines.||End of AAA group.||]

              Of course, this will end in a wrong sorting because the first line doesn't start with '||'.

              Working with data structure I derived from your first message I get to correct results with...

              ^!Jump 1
              ^!InsertText ||
              ^!Replace "^P" >> "||" WAS
              ^!Replace "]" >> "]^P" WAS
              ^!Toolbar Sort Ascending
              ^!Replace "(?<!^)\|\|" >> "\r\n" WARS
              ^!Replace "||" >> "" WAS

              Well -- "many roads lead to Rome". At least I learned how a shorter clip will lead to the same result.

              Flo
            • John Shotsky
              I see what is happening. I used a clip to pull the first line after [ onto that line, followed by ||, and THEN used the replace on the rest of the CR s. I had
              Message 6 of 9 , Sep 5, 2011
              • 0 Attachment
                I see what is happening. I used a clip to pull the first line after [ onto that line, followed by ||, and THEN used the
                replace on the rest of the CR's. I had so much extra stuff going on in mine that it wasn't 'simple enough' to post. But
                your solution works too, by simply adding one more || at the beginning.

                Regards,
                John

                From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of flo.gehrke
                Sent: Monday, September 05, 2011 15:18
                To: ntb-clips@yahoogroups.com
                Subject: Re: [Clip] Sorting groups?


                --- In ntb-clips@yahoogroups.com <mailto:ntb-clips%40yahoogroups.com> , "John Shotsky" <jshotsky@...> wrote:
                >
                > You didn't misunderstand, your solution does work, but it
                > is actually more complex than the one I settled on.
                > In mine, I just replaced all CRLF with ||, and then added back
                > a CRLF after each ]. That gives one line per section with
                > || as delimiters between the original lines. In your example,
                > you would have just 4 lines.
                >
                > If you insert a GoTo Exit before Select all, you should see one
                > line per section, starting with [ and ending with ]. It
                > even preserves blank lines, as intended.
                > Then you just sort those lines and replace the || with CRLF,
                > and add a CRLF after [.

                Thanks John!

                I can't confirm this, though your remarks correspond exactly with the clip I made following Art's advice. The result is
                still the mess I described.

                The only explanation I have for this is that, probably, the original data structure you posted with message #22045 isn't
                valid any more.

                For example: After...

                ^!Replace "^P" >> "||" WAS
                ^!Replace "]" >> "]^P" WAS

                the result is...

                [||DDD group.||More lines.||More lines.||End of DDD group||]
                ||[||CCC group.||More lines.||More lines.||End of CCC group||]
                ||[||BBB group.||More lines.||More lines.||End of BBB group.||]
                ||[||AAA group.||More lines.||More lines.||End of AAA group.||]

                Of course, this will end in a wrong sorting because the first line doesn't start with '||'.

                Working with data structure I derived from your first message I get to correct results with...

                ^!Jump 1
                ^!InsertText ||
                ^!Replace "^P" >> "||" WAS
                ^!Replace "]" >> "]^P" WAS
                ^!Toolbar Sort Ascending
                ^!Replace "(?<!^)\|\|" >> "\r\n" WARS
                ^!Replace "||" >> "" WAS

                Well -- "many roads lead to Rome". At least I learned how a shorter clip will lead to the same result.

                Flo



                [Non-text portions of this message have been removed]
              • Art Kocsis
                Flo, My BAD!!! I didn t worry about all the extra || s as they would not affect the sort and would be deleted afterwards. Well, obviously the lack of an
                Message 7 of 9 , Sep 5, 2011
                • 0 Attachment
                  Flo,

                  My BAD!!!

                  I didn't worry about all the extra "||"s as they "would not affect the
                  sort" and
                  would be deleted afterwards.

                  Well, obviously the lack of an initial "||" in the first line DID affect
                  the sort. Sorry.
                  As soon as I saw your debug results the error was obvious.

                  This illustrates the fallibility of "thought programming" and the value of
                  the debugger.

                  Glad you caught it.

                  Namaste', Art

                  Some days it's just not worth chewing through the restraints!


                  At 09/05/2011 15:18, you wrote:
                  >I can't confirm this, though your remarks correspond exactly with the clip
                  >I made following Art's advice. The result is still the mess I described.
                  >
                  >The only explanation I have for this is that, probably, the original data
                  >structure you posted with message #22045 isn't valid any more.
                  >
                  >For example: After...
                  >
                  >^!Replace "^P" >> "||" WAS
                  >^!Replace "]" >> "]^P" WAS
                  >
                  >the result is...
                  >
                  >[||DDD group.||More lines.||More lines.||End of DDD group||]
                  >||[||CCC group.||More lines.||More lines.||End of CCC group||]
                  >||[||BBB group.||More lines.||More lines.||End of BBB group.||]
                  >||[||AAA group.||More lines.||More lines.||End of AAA group.||]
                  >
                  >Of course, this will end in a wrong sorting because the first line doesn't
                  >start with '||'.
                  >
                  >Working with data structure I derived from your first message I get to
                  >correct results with...
                  >
                  >^!Jump 1
                  >^!InsertText ||
                  >^!Replace "^P" >> "||" WAS
                  >^!Replace "]" >> "]^P" WAS
                  >^!Toolbar Sort Ascending
                  >^!Replace "(?<!^)\|\|" >> "\r\n" WARS
                  >^!Replace "||" >> "" WAS
                  >
                  >Well -- "many roads lead to Rome". At least I learned how a shorter clip
                  >will lead to the same result.
                  >
                  >Flo
                Your message has been successfully submitted and would be delivered to recipients shortly.