This is a pedestrian solution from a non-coder, just done step by step, so I can check if I’m getting the expected result and backing up if not. Fortunately BBEdit is zippy quick and believes in CMD-Z. I’m sure someone who has actual skills will supply a more elegant solution.
convert spaces to tabs - email text has spaces replace ^\t\t with nothing - (strips out the 2 leading tabs at the beginning of each line) replace \t\t with \t@ - all remaining double tabs reduced to one tab and @ replace \n\t with @ - all indented items are now in the line following the term to be alphabetized, with the indentation tier coded as @s sort lines - as it says on the tin replace @@ with @\t - decodes second-tier terms by one tab replace @ with \n\t - finishes replacing the tabs and puts terms back on their own lines This assumes that there ar no more than two indented levels, and that the indented terms are wanted in their existing order. Doing the alphabetizing on those levels would have to deal with disregarding the brackets, and I suspect that a clever data structure would help. Note that input data errors do exist: "elegant" should probably be on its own line, unindented, for example, so you may have a few more things to account for. Greg > On Oct 8, 2022, at 5:22 PM, Media Mouth <[email protected]> wrote: > > Following. Sure is an interesting challenge. > > It'll be cool of someone with mad GREP skills has a brilliant solution. > What seems like might work more easily would be to convert the lists to JSON > data, merge them, then sort, then convert back to the tabbed format of your > example. > > Out of curiosity, what system is making use of keyword formatting in your > example. Photo Mechanic? Wondering if it's mostly proprietary or if it's a > standard keyword categorization system that's in wider use. > > - MM > > > >> On Oct 8, 2022, at 1:57 PM, Matthew Bender <[email protected]> >> wrote: >> >> Hi all, >> >> I'm a photographer, and my experience sorting with GREP is incredibly >> minimal. If this can't be done - apologies! >> >> I'm building a structured hierarchal keyword list for stock photography >> purposes. I aquired two separate pre-assembled lists. Both did certain >> things better than the other. I want to combine keyword groups across these >> two lists into one large, alphabetized group that maintains the established >> hierarchy. >> >> Most keywords are simply words, but a few involve numbers (#1, for >> example.). Being hierarchal, it's been built out using tabs to communicate >> nested levels and curly brackets to communicate synonyms. An example is >> below, the spaces are all tabs. >> >> ambition >> {ambitious} >> ancient >> train >> ancient civilization >> apex >> {#1} >> {number 1} >> appetizing >> apprehend >> approach >> {approaching} >> approachable >> approval >> {approve} >> {approving}elegant >> email >> embryonic >> emotion >> {emotional} >> {emotions} >> affection >> devotion >> fondness >> love >> passion >> sympathy >> tenderness >> warmth >> agitated >> {agitation} >> flustered >> frantic >> amusement >> {amused} >> {amusing} >> ego >> elegance >> embarrassment >> emergence >> empathy >> emphasis >> enchantment >> encouragement >> ending >> endurance >> energy >> enhancement >> enjoyment >> ennui >> enthusiasm >> envy >> equality >> >> This example shows what I'd like to do - I want to merge the bottom set (ego >> to equality, this came from one list) into the top set (ambition to emotion, >> this came from the other list) alphabetically while maintaining the synonyms >> and nested structure. Is there a way to just sort data on the 'top layer' >> alphabetically (and accounting for the 1% of kewords that are things like #1 >> and the special characters like the curly brackets) while maintaining the >> established hierarchy? My attempts so far leave things alphabetically >> ordered, but the nested layers and top layers get all jumbled together and >> the structure is completely broken. It alphabetizes every single word, which >> isn't what I want at all. >> >> Any help or tips would be much appreciated. >> >> Thanks, >> -Matt >> >> >> -- >> This is the BBEdit Talk public discussion group. If you have a feature >> request or need technical support, please email "[email protected]" >> rather than posting here. Follow @bbedit on Twitter: >> <https://twitter.com/bbedit> >> --- >> You received this message because you are subscribed to the Google Groups >> "BBEdit Talk" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/bbedit/d43d48c6-3181-457c-a29b-53f7a8ca5f8fn%40googlegroups.com. > > > -- > This is the BBEdit Talk public discussion group. If you have a feature > request or need technical support, please email "[email protected]" > rather than posting here. Follow @bbedit on Twitter: > <https://twitter.com/bbedit> > --- > You received this message because you are subscribed to the Google Groups > "BBEdit Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/bbedit/E6A4757E-1078-4F2B-8CCE-F5FECB95292C%40gmail.com. -- This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "[email protected]" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit> --- You received this message because you are subscribed to the Google Groups "BBEdit Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/0DB554C9-1A9D-4708-8374-50BCFAA32AF4%40zizania.org.
