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

Re: sorting lines by means of a part

Expand Messages
  • flo.gehrke
    ... Adrien, The following clip might come pretty close to a solution of this task. It s derived from a clip I wrote for a similar job. I understand that task
    Message 1 of 6 , Apr 7 9:12 PM
    • 0 Attachment
      --- In ntb-clips@yahoogroups.com, Adrien Verlee <adrien.verlee@...> wrote:
      >
      > After watching the help file on clips, I must conclude that this is
      > no longer for me. So I hope that someone would help me.
      >
      > It is sorting of lines via a part of each line. Each line contains
      > a ":" (1 colon). Before and after the colon, there is all kinds of
      > text, including figures, punctuation marks, spaces, and
      > ordinary letters.
      > - The lines should be sorted as a whole, but what is left of
      > the colon determines the sorting...


      Adrien,

      The following clip might come pretty close to a solution of this task. It's derived from a clip I wrote for a similar job.

      I understand that task as follows: The lines are divided into a left and a right string and have to get sorted on two levels. On first level, sort the left strings on their string size. On second level, sort the right strings alphabetically.

      Running the following clip against your sample text seems to achieve the desired result.

      Please note:

      1. Only one document containing the source text should be opened because the clip toggles between the source and a second document used as text buffer.

      2. The source text will be changed by the clip. So make sure to save your original version.

      3. The sorting on string size supposes that the maximum length of the left strings is 99 characters.


      ^!Jump Doc_Start
      ^!SetScreenUpdate Off

      :Insert_StrSize
      ^!Find "^[^:]+" RS
      ^!IfError Sort_left
      ^!InsertText ^$StrSize(^$GetSelection$)$^%Space%^$GetSelection$
      ^!Goto Insert_StrSize

      :Sort_left
      ; Sort descending on length of string size
      ^!Replace "^(?=\d\x20)" >> "0" AWRS
      ^!Select All
      ^$StrSort("^$GetSelection$";0;0;0)$
      ^!Jump Doc_Start
      ^!Toolbar New Document
      ^!Document First

      :Sort_right
      ; Alpha-sort ascending on string right
      ; Capture lines with equal StrSize left
      ^!Find "^(\d{2}).*\R(\1.*(\R|\Z))+" RS
      ^!IfError Out
      ; Copy block to text buffer
      ^!SetClipboard ^$GetSelection$
      ^!Document Next
      ^!Select All
      ^!Paste
      ^!Replace "^([^:]+):(.+)$" >> "$2:$1" WARS
      ^!Select All
      ^$StrSort("^$GetSelection$";0;1;0)$
      ^!Replace "^([^:]+):(.+)$" >> "$2:$1" WARS
      ; Remove empty lines at end of string
      ^!Replace "\R{1,}\Z" >> "" WRS
      ^!SetClipboard ^$GetText$
      ^!Document First
      ^!InsertText ^$GetClipboard$^P
      ^!Goto Sort_right

      :Out
      ^!Document Next
      ^!Close Discard
      ^!Replace "^\d{1,}\x20" >> "" WARS
      ^!Jump Doc_Start

      To watch what the clip is doing, change the second line to '^!ScreenUpdate On' and run the clip in debug mode (^!SetDebug On).

      Regards,
      Flo
    • Adrien Verlee
      ... Thanks Flo and Don ! -- Adrien
      Message 2 of 6 , Apr 8 5:07 AM
      • 0 Attachment
        Op 8/04/2012 6:12, flo.gehrke schreef:
        > Running the following clip against your sample text seems to achieve the desired result.

        Thanks Flo and Don !
        --
        Adrien
      Your message has been successfully submitted and would be delivered to recipients shortly.