Sorting/alphabetizing sections/blocks in an .ini file?

2014-02-23
2014-02-23
  • chinagreenelvis

    chinagreenelvis - 2014-02-23

    Example:

    [Section2]
    Item4
    Item3
    [Section1]
    Item2
    Item1

    Using TextFX to sort the lines separates the items from the sections. Is there any way to quickly organize an .ini file so that the result is

    [Section1]
    Item1
    Item2
    [Section2]
    Item3
    Item4

    Alphabetizing the items isn't as important to me as getting the sections in order.

     
  • dail8859

    dail8859 - 2014-02-23

    There may be an easier way I don't know of but this is how I would go about sorting the Sections.

    Since sorting with TextFX (and N++ has sorting built in after v6.5.2) always looks at each line instead of within a section, merge the entire section into a single line with search/replace by inserting a special character between items (in this case the tilde character). Search for (with the Regular Expression option enabled):

    \r\n([^\[])
    

    and replace it with:

    ~\1
    

    Note, depending on what all characters are in your file, you may want to use some other character that is not present anywhere else in your file.

    After that is complete you can sort your file. The next thing to do is remove the special characters with newlines

    Find the special character you inserted (turn on the Extended option):

    ~
    

    And replace it with

    \r\n
    

    And this should at least have your sections sorted.

     
    Last edit: dail8859 2014-02-23