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

Re: [Clip] sorting lines by means of a part

Expand Messages
  • Don
    On second thought you need to determine lengths, insert zero padded lengths in the first column, sort on that, remove them, and then remove the numbers. ... I
    Message 1 of 6 , Apr 7, 2012
      On second thought you need to determine lengths, insert zero padded
      lengths in the first column, sort on that, remove them, and then remove
      the numbers. ...

      I have a clip that will order columns alpha and I just ran it on yours
      ... not what you want:
      ~$#..w6ek?t:weekwinst
      zuid-oostelijke:zuidoostelijk
      zog.:zg.
      zo even:zo-even
      zilver uitvoer:zilveruitvoer
      zijden:zijden/kanten
      zijde:zijde/kant
      zetelrover:afperser
      wereld-geldmarkt:wereldgeldmarkt
      wereld-geld:wereldgeld
      welstandsinstelling:liefdadigheidsinstelling
      weg te zwendelen:weg te toveren
      weerstreeft:tegenwerkt/knor/armen/werken tegen/toeslaan
      warenquantum:warenkwantum
      r1:1r
      0123456789:uitgegeven/weggegeven

      On 4/7/2012 11:06 AM, Adrien Verlee wrote:
      > So the longest text to the left of the colon, is top of the list,
      > the shortest at the bottom.
    • Don
      Okay I have length sorting ... If you want to sort within length you need one more loop in there to find all that have same length and then sort within ... I
      Message 2 of 6 , Apr 7, 2012
        Okay I have length sorting ...
        If you want to sort within length you need one more loop in there to
        find all that have same length and then sort within ... I capped it a
        10000 lines but easy to up that.

        My results:
        welstandsinstelling:liefdadigheidsinstelling
        wereld-geldmarkt:wereldgeldmarkt
        weg te zwendelen:weg te toveren
        zuid-oostelijke:zuidoostelijk
        zilver uitvoer:zilveruitvoer
        warenquantum:warenkwantum
        ~$#..w6ek?t:weekwinst
        wereld-geld:wereldgeld
        weerstreeft:tegenwerkt/knor/armen/werken tegen/toeslaan
        zetelrover:afperser
        0123456789:uitgegeven/weggegeven
        zo even:zo-even
        zijden:zijden/kanten
        zijde:zijde/kant
        zog.:zg.
        r1:1r

        ^!SetHintInfo ReOrdering...
        ^!SetScreenUpdate Off
        ^!Set %Delimiter%=^?{Enter Delimiter: : ^p ^t ; @ , Tab
        shown=_:|^p|^%VBAR%|^||^t|;|@|,}

        ^!Jump Doc_Start

        :Loop1
        ^!Select Eol
        ^!IfFalse ^$IsEmpty(^%IsSelected%)$ Skip_5
        ^!Find "^%Delimiter%" TIHS
        ^!Set %SortLength%=^$GetCol$
        ^!Jump Line_Start
        ^!InsertText 000000^%SortLength%|:|
        ^!If ^$GetRow$ <> ^$GetLineCount$ Next else Loop2
        ^!Jump +1
        ^!Goto Loop1

        :Loop2
        ^!replace "^0*(\d{5})" >> "$1" rwais
        ^!Select All
        ^$StrSort("^$GetSelection$";No;No;Yes)$
        ^!Replace "^.*\|\:\|" >> "" RAWS



        On 4/7/2012 11:06 AM, Adrien Verlee wrote:
        > - The lines should be sorted as a whole, but what is left of the colon
        > determines the sorting.
      • 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 3 of 6 , Apr 7, 2012
          --- 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 4 of 6 , Apr 8, 2012
            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.