Sorting Folded Lines (Blocks?)



  • Hey All,

    I did a quick search through google and the search function on this forum but couldn’t find anything on the surface so sorry if this has been asked before.

    I’m working with an xml type file (.yaml actually) and I’ve got a bunch of data folded under different lines that act as catagories. What I’m looking to do is sort everything on level 1 but keep the associated data from level 2 and so on with its respected level 1.

    TLDR, does anyone know how I can sort a bunch of folded lines (would that be a block) and keep the associated data within the fold attached to level 1?

    Sorry if that doesn’t make sense.



  • Hello Justin,

    I’ve thought about a method that will use, successively, a regular expression search/replacement, a classical alphabetic sort and;, finally, an other regex S/R.

    However , could you provide us a part of your .yaml file, to get a better idea of your goal ? Thanks !

    Best Regards,

    guy038



  • Thanks for the response guy,

    The .yaml is linked here. The section I’m trying to sort is the ‘presets section’ with the special characters (✥,★,♞, etc…)



  • Edit, you asked for a small portion of the code. I’m sure you know this, buy .yaml is space sensitive, so I hope adding in the ‘code’ function of this board didn’t affect the formatting any.

    presets:
    - - '★ friendly: logistic'
     - - - alwaysShownStates
      - - 11
        - 12
        - 14
        - 15
        - 16
        - 45
        - 49
    - - filteredStates
      - - 9
        - 10
        - 13
        - 17
        - 18
        - 19
        - 20
        - 21
        - 36
        - 37
        - 44
        - 48
        - 50
        - 51
        - 52
        - 53
    - - groups
      - - 6
        - 90
        - 361
        - 479
        - 492
        - 547
        - 548
        - 832
        - 863
        - 864
        - 1527
     - - '♞ hostile: carriers'
     - - - alwaysShownStates
      - []
    - - filteredStates
      - - 11
        - 12
        - 14
        - 15
        - 16
        - 21
        - 45
        - 49
    - - groups
      - - 90
        - 547
        - 863
        - 864
        - 1538
    - - '★ friendly: dreads'
      - - - alwaysShownStates
      - - 11
        - 12
        - 14
        - 15
        - 16
        - 45
        - 49
    - - filteredStates
      - - 9
        - 10
        - 13
        - 17
        - 18
        - 19
        - 20
        - 21
        - 36
        - 37
        - 44
        - 48
        - 50
        - 51
        - 52
        - 53
    - - groups
      - - 6
        - 90
        - 361
        - 479
        - 485
        - 492
        - 548
        - 863
        - 864
    - - '♞ hostile: battlecruisers'
      - - - filteredStates
      - - 11
        - 12
        - 14
        - 15
        - 16
        - 21
        - 45
        - 49
    - - groups
      - - 90
        - 419
        - 540
        - 863
        - 864
        - 1201
    - - '♞ hostile: antibombers (!)'
     - - - filteredStates
      - - 11
        - 12
        - 14
        - 15
        - 16
        - 21
        - 45
        - 49
    - - groups
      - - 834


  • Hi Justin,

    Firstly, I downloaded the entire contents of your .yaml file ( 5175 lines )

    Secondly, I isolated the Presets section ( 4925 lines )

    Thirdly, I understood that your special characters belongs :

    Fourthly, I only, extracted the lines which contain one of these special Unicode characters. I got a list of 51 items, below :

    - - '✥  --- dscan: ships'
    - - '★ friendly: logistic'
    - - '♞ hostile: carriers'
    - - '★ friendly: dreads'
    - - '♞ hostile: battlecruisers'
    - - '♞ hostile: antibombers (!)'
    - - '♣ pve: salvage/loot'
    - - '★ friendly: capitals'
    - - '♞ hostile: fighters/fibos'
    - - '♞ hostile: dictors'
    - - ❏ hostile brackets
    - - '★  friendly: fleet'
    - - '♞  wartargets only'
    - - '★ friendly: sc/t'
    - - '♞   --- normal pvp'
    - - '✥ dscan: pos all mods'
    - - '♞ hostile: cruisers'
    - - '♣ pve: mining'
    - - '♞ hostile: logistics'
    - - ❏ no brackets
    - - ❏ skirmish brackets
    - - '✪ extra: podsaver (!)'
    - - '♞ hostile: cmd dest'
    - - '★ friendly: recons'
    - - '♞ hostile: drones'
    - - '✈ travel: show all'
    - - '♞ hostile: dreads'
    - - '♞ hostile: titans'
    - - '♞  structures'
    - - '♞ hostile: frig/dest'
    - - '♞ hostile: supers/titans'
    - - '♞  deployables'
    - - '♞ hostile: recons'
    - - '✈ travel: hide stations'
    - - '♣ pve: anoms/ratting'
    - - '♞ hostile: supercarriers'
    - - '♞  bombing warpouts'
    - - '♣ pve: show drones'
    - - '★ friendly: dictors'
    - - '★  --- friendly: all'
    - - '✈  --- basic travel'
    - - '♞ hostile: caps'
    - - ♣  --- basic pve
    - - ❏ default brackets
    - - '♞  npsi'
    - - '♞ hostile: cs/t3'
    - - '♞ hostile: battleships'
    - - '✥ dscan: pos'
    - - '♞  - ships only'
    - - '★ friendly: carriers'
    - - '✪ extra: align points'
    

    Finally, I performed a classical sort ( Menu Edit - Line Operations - Sort Lines Lexicographically Ascending ) and I got the list below :

    - - '★  --- friendly: all'
    - - '★  friendly: fleet'
    - - '★ friendly: capitals'
    - - '★ friendly: carriers'
    - - '★ friendly: dictors'
    - - '★ friendly: dreads'
    - - '★ friendly: logistic'
    - - '★ friendly: recons'
    - - '★ friendly: sc/t'
    - - '♞   --- normal pvp'
    - - '♞  - ships only'
    - - '♞  bombing warpouts'
    - - '♞  deployables'
    - - '♞  npsi'
    - - '♞  structures'
    - - '♞  wartargets only'
    - - '♞ hostile: antibombers (!)'
    - - '♞ hostile: battlecruisers'
    - - '♞ hostile: battleships'
    - - '♞ hostile: caps'
    - - '♞ hostile: carriers'
    - - '♞ hostile: cmd dest'
    - - '♞ hostile: cruisers'
    - - '♞ hostile: cs/t3'
    - - '♞ hostile: dictors'
    - - '♞ hostile: dreads'
    - - '♞ hostile: drones'
    - - '♞ hostile: fighters/fibos'
    - - '♞ hostile: frig/dest'
    - - '♞ hostile: logistics'
    - - '♞ hostile: recons'
    - - '♞ hostile: supercarriers'
    - - '♞ hostile: supers/titans'
    - - '♞ hostile: titans'
    - - '♣ pve: anoms/ratting'
    - - '♣ pve: mining'
    - - '♣ pve: salvage/loot'
    - - '♣ pve: show drones'
    - - '✈  --- basic travel'
    - - '✈ travel: hide stations'
    - - '✈ travel: show all'
    - - '✥  --- dscan: ships'
    - - '✥ dscan: pos all mods'
    - - '✥ dscan: pos'
    - - '✪ extra: align points'
    - - '✪ extra: podsaver (!)'
    - - ♣  --- basic pve
    - - ❏ default brackets
    - - ❏ hostile brackets
    - - ❏ no brackets
    - - ❏ skirmish brackets
    

    Notes :

    • You’ll notice that most of these “header” lines begin with the string - - '

    • Only five lines, which have a special character, instead of the single quote, are, of course, moved at the end of the sorted list.

    • And, generally speaking, all these special Unicode characters are sorted, according to their Unicode number ( 2605 for the Black Star, 265E for the Black Chess Knight, and so on… )

    So, If you agree, with that specific sort ( May be, at the end, you’ll have to move one or few blocks to an other place ! ) I’ll give you, next time, the complete method to get the sorted list of these “header” lines with ( the most important ! ) all their contents unchanged :-))

    Cheers

    guy038


Log in to reply