Special sorting
-
Hello.
I’m looking for help with text sorting. I have a large datapack (60k+ rows) that is not sorted by ID.
I tried using the standard sorting functions by numeric value, but since in the skill_name=[…] section there are also different letters and numbers - this breaks sorting.
Is there any way to sort rows by numeric value inside skill_id=[…]? or is it impossible in NPP++ and I need to write a parser for sorting it?Thanks in advance for your replies.
-
any way to sort rows by numeric value inside skill_id=[…]? or is it impossible in NPP++ and I need to write a parser for sorting it?
You need to resort to programming to achieve such a goal. If you want to do it within Notepad++, then scripting plugins are available to help achieve it.
-
Hello, @vavoices, @alan-kilborn and All,
There is an easy solution to your problem. You just have to, temporarily, copy all the fields, which need sorting, at the beginning of curent line, accordingly to their sorting order ;-))
For instance, starting with this INPUT text ( dummy text to illustrate the technique ! ) :
skill_begin skill_name=[auto belt1] skill_id=10022 level=1 operate_type=P magic skill_begin skill_name=[auto_belt2] skill_id=10023 level=1 operate_type=P magic skill_begin skill_name=[auto_belt3] skill_id=10024 level=1 operate_type=P magic skill_begin skill_name=[auto_belt4] skill_id=10025 level=1 operate_type=P magic skill_begin skill_name=[br_s_item_herb_of_ginseng_recovery] skill_id=22004 level=1 skill_begin skill name=[br_s_item_herb_of_ginseng_vp_up] skill_id=22005 level=2 skill_begin skill_name=[br_s_item_herb_of_ginseng_recovery] skill_id=22004 level=7 skill_begin skill_name=[br_s_item_herb_of_ginseng_recovery] skill_id=22004 level=8 skill_begin skill_name=[br_s_item_herb_of_kimchi_power_a] skill_id=22000 level=3 sklll_begin skill_name=[br_s_item_herb_of_kimchi_power_b] skill_id=22001 level=4 skill_begin skill_name=[br_s_item_herb_of_kimchi_power_c] skill_id=22002 level=4 skill_begin skill_name=[br_s_item_herb_of_ginseng_recovery] skill_id=22004 level=9 skill_begin skill_name=[br_s_item_herb_of_kimchi_time] skill_id=22003 level=1 skill_begin skill_name=[chain_hydral] skill_id=18230 level=1 operate_type=A2 skill_begin skill_name=[chain_hydra2] skill_id=18230 level=2 operate_type=A2 sklll_begin skill_name=[chain_hydra3] skill_id=18230 level=3 operate_type=A2 skill_begin skill_name=[chain_hydra4] skill_id=18230 level=4 operate_type=A2
Let’s suppose that you want to sort these lines, in ascending direction, by
skill_id
values and bylevel
valuesThen, perform the following regex S/R :
SEARCH
(?x-is) ^ .* \b ( skill_id= \d+ ) .+ \b ( level= \d ) \b .*
REPLACE
$1 $2 $0
you’ll get this temporary text :
skill_id=10022 level=1 skill_begin skill_name=[auto belt1] skill_id=10022 level=1 operate_type=P magic skill_id=10023 level=1 skill_begin skill_name=[auto_belt2] skill_id=10023 level=1 operate_type=P magic skill_id=10024 level=1 skill_begin skill_name=[auto_belt3] skill_id=10024 level=1 operate_type=P magic skill_id=10025 level=1 skill_begin skill_name=[auto_belt4] skill_id=10025 level=1 operate_type=P magic skill_id=22004 level=1 skill_begin skill_name=[br_s_item_herb_of_ginseng_recovery] skill_id=22004 level=1 skill_id=22005 level=2 skill_begin skill name=[br_s_item_herb_of_ginseng_vp_up] skill_id=22005 level=2 skill_id=22004 level=7 skill_begin skill_name=[br_s_item_herb_of_ginseng_recovery] skill_id=22004 level=7 skill_id=22004 level=8 skill_begin skill_name=[br_s_item_herb_of_ginseng_recovery] skill_id=22004 level=8 skill_id=22000 level=3 skill_begin skill_name=[br_s_item_herb_of_kimchi_power_a] skill_id=22000 level=3 skill_id=22001 level=4 sklll_begin skill_name=[br_s_item_herb_of_kimchi_power_b] skill_id=22001 level=4 skill_id=22002 level=4 skill_begin skill_name=[br_s_item_herb_of_kimchi_power_c] skill_id=22002 level=4 skill_id=22004 level=9 skill_begin skill_name=[br_s_item_herb_of_ginseng_recovery] skill_id=22004 level=9 skill_id=22003 level=1 skill_begin skill_name=[br_s_item_herb_of_kimchi_time] skill_id=22003 level=1 skill_id=18230 level=1 skill_begin skill_name=[chain_hydral] skill_id=18230 level=1 operate_type=A2 skill_id=18230 level=2 skill_begin skill_name=[chain_hydra2] skill_id=18230 level=2 operate_type=A2 skill_id=18230 level=3 sklll_begin skill_name=[chain_hydra3] skill_id=18230 level=3 operate_type=A2 skill_id=18230 level=4 skill_begin skill_name=[chain_hydra4] skill_id=18230 level=4 operate_type=A2
Now, run the
Edit > Line Operations > Sort lines lexicographically Ascending
N++ optionskill_id=10022 level=1 skill_begin skill_name=[auto belt1] skill_id=10022 level=1 operate_type=P magic skill_id=10023 level=1 skill_begin skill_name=[auto_belt2] skill_id=10023 level=1 operate_type=P magic skill_id=10024 level=1 skill_begin skill_name=[auto_belt3] skill_id=10024 level=1 operate_type=P magic skill_id=10025 level=1 skill_begin skill_name=[auto_belt4] skill_id=10025 level=1 operate_type=P magic skill_id=18230 level=1 skill_begin skill_name=[chain_hydral] skill_id=18230 level=1 operate_type=A2 skill_id=18230 level=2 skill_begin skill_name=[chain_hydra2] skill_id=18230 level=2 operate_type=A2 skill_id=18230 level=3 sklll_begin skill_name=[chain_hydra3] skill_id=18230 level=3 operate_type=A2 skill_id=18230 level=4 skill_begin skill_name=[chain_hydra4] skill_id=18230 level=4 operate_type=A2 skill_id=22000 level=3 skill_begin skill_name=[br_s_item_herb_of_kimchi_power_a] skill_id=22000 level=3 skill_id=22001 level=4 sklll_begin skill_name=[br_s_item_herb_of_kimchi_power_b] skill_id=22001 level=4 skill_id=22002 level=4 skill_begin skill_name=[br_s_item_herb_of_kimchi_power_c] skill_id=22002 level=4 skill_id=22003 level=1 skill_begin skill_name=[br_s_item_herb_of_kimchi_time] skill_id=22003 level=1 skill_id=22004 level=1 skill_begin skill_name=[br_s_item_herb_of_ginseng_recovery] skill_id=22004 level=1 skill_id=22004 level=7 skill_begin skill_name=[br_s_item_herb_of_ginseng_recovery] skill_id=22004 level=7 skill_id=22004 level=8 skill_begin skill_name=[br_s_item_herb_of_ginseng_recovery] skill_id=22004 level=8 skill_id=22004 level=9 skill_begin skill_name=[br_s_item_herb_of_ginseng_recovery] skill_id=22004 level=9 skill_id=22005 level=2 skill_begin skill name=[br_s_item_herb_of_ginseng_vp_up] skill_id=22005 level=2
You can verify that all the lines :
-
Are first sorted by
skill_id
values ascending, then bylevel
values ascending -
And, for a same
skill_id
key, are sorted bylevel
values ascending ( case ofskill_id=22004
)
Finally, run this final regex S/R, in order to delete the temporary leading keys :
SEARCH
(?x-is) ^ .+ (?= skill_begin )
REPLACE
Leave EMPTY
And here is your expected OUTPUT text :
skill_begin skill_name=[auto belt1] skill_id=10022 level=1 operate_type=P magic skill_begin skill_name=[auto_belt2] skill_id=10023 level=1 operate_type=P magic skill_begin skill_name=[auto_belt3] skill_id=10024 level=1 operate_type=P magic skill_begin skill_name=[auto_belt4] skill_id=10025 level=1 operate_type=P magic skill_begin skill_name=[chain_hydral] skill_id=18230 level=1 operate_type=A2 skill_begin skill_name=[chain_hydra2] skill_id=18230 level=2 operate_type=A2 skill_id=18230 level=3 sklll_begin skill_name=[chain_hydra3] skill_id=18230 level=3 operate_type=A2 skill_begin skill_name=[chain_hydra4] skill_id=18230 level=4 operate_type=A2 skill_begin skill_name=[br_s_item_herb_of_kimchi_power_a] skill_id=22000 level=3 skill_id=22001 level=4 sklll_begin skill_name=[br_s_item_herb_of_kimchi_power_b] skill_id=22001 level=4 skill_begin skill_name=[br_s_item_herb_of_kimchi_power_c] skill_id=22002 level=4 skill_begin skill_name=[br_s_item_herb_of_kimchi_time] skill_id=22003 level=1 skill_begin skill_name=[br_s_item_herb_of_ginseng_recovery] skill_id=22004 level=1 skill_begin skill_name=[br_s_item_herb_of_ginseng_recovery] skill_id=22004 level=7 skill_begin skill_name=[br_s_item_herb_of_ginseng_recovery] skill_id=22004 level=8 skill_begin skill_name=[br_s_item_herb_of_ginseng_recovery] skill_id=22004 level=9 skill_begin skill name=[br_s_item_herb_of_ginseng_vp_up] skill_id=22005 level=2
Now, just tell me how you would like your file sorted and if all your numbers contain the same number of digits
See you later !
Best Regards,
guy038
-
-
This post is deleted! -
This post is deleted! -
This post is deleted!