Sorting text
-
I have a file that contains a large number of song lyrics. Each lyric has the song title followed by a blank line, then by the all the words of the lyric. The next lyric starts after 4 blank lines, the next after another 4 lines and so on. Is there a way to sort these lyrics (by the song titles) alphabetically? Thanks for any help.
-
Your problem seems more of a database manipulation than text editor.
Sorting chunks (groups of lines) rather than single lines will take more effort on your part.
If you absolutely must use a text editor, then I would suggest crafting a regex that joins the n lines of your chunk with some character not in your data (😀 is my typical choice); making sure that during your join , you order things so that the sorting key is the first entry on the line. Once joined, then do the sort. After sorting, use another regex to split on 😀, and reorder if necessary.
Before handing you a regex that might meet your needs, I would need you to supply example data… Otherwise, I’ll waste everyone’s time guessing what your data looks like, and missing some subtlety that I misunderstood. See the FAQ for a template for search/replace questions, linked below, to make sure your example data is formatted correctly.
----
Useful References