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
-
Hi PeterJOnes: Sorry for the delay in my response. I had misplaced the link to this page and just now found it.
Attached are two sets of song lyrics, one is unsorted and the other sorted.
The complete file is large and has over 30000 song lyrics. Thanks for any help.UNSORTED
unnAlE enna Agum. rAgA: asAvEri. cApu tALA. Desiya Vinayakam Pillai.
P: unnAlE enna Agum Ezhai manida unnAlE enna Agum
A: nannArppUTTi oru nAyakan ATTi allAl tannAlE ADum pAvai dharaNiyil engumuNDO
C: ellAm iyaTrudarkku vallAn em maraikkumE sollAl aLavaruttu sollarkkariya pirAn
nallArkkum pollArkkum naDu ninru naTam seyum allArum kaNDanavan aruLaip-perAdirundAlnAda sudhArasa. rAgA: kAmavardhani. rUpaka tALA. composer not known.
P: nAda sudhArasa rasikE mAm pAhi mahA tripurasundari pAhi
A: vEda purANa nAda sudhAtmikE bhakta janArcita gIta guNAlayE
C: rAkendu sundara manda hasitE karuNAjaladhE kanakAdrivAsE
gIta vAdya (san) rasikapriyE harihara pUritE manda hasitEbhajana sEyavE O. rAgA: kIravANi. Adi tALA. A.S.Krishnamurti & Shanta Radhakrishnan.
P: bhajana sEyavE O manasA bhajana sEyavE rAdhA lOluni parama dayALuni
A: bhavarOga bhESajamaina bhakta paripAluni pankajAkSuni parama pavitruni
C: gpAla bAluni gOdAnAthuni guru sanjIvAmrta rasikuni bhakti bhAvarAga layamu gUrcivarai illAmal. rAgA: AbhEri. / cApu tALA. Kovai Subri.
P: varai illAmal aruLai vAri vazhangiDuvAn tirai kaDark-karaiyOram uraivOn aDiyArkku
A: kurai tam adai eDuttu kUrit-tannai aDuttu tiruccendUr vandu darishittiDuvOrkku
C: aDuttaDuttu OyAdu alai pAivadaip-pOl aDuttaDuttu OyAdu aDi tozha varuvOrkku
koDaikkaram OyAdu koDuttiDa sOrAdOn paDai vIDugaL Aru paDaittiTTa pErALanjnAna maNTapam tannil. rAgA: kalyANi. Adi tALA. Parvati Ammal.
P: jnAna maNTapam tannil jnAnAnada rUpiyai dhyAnam seivOm vArum nAdasvarUpa
A: jnAnOpadEsham seidu jnyAlattuyiraik-kArppAL tAnE tAnAi viLangum sadguruvAga nirppAL
C: vAnattu mazhai pOl vADum bhaktagaLaik-kArppAL kanal jalam pOL kANum ivvulagenbAn
mOnattirundu nIyum mukti aDaiyenbAL tEnAi soriyum divya sadguru upadEshaSORTED
bhajana sEyavE O. rAgA: kIravANi. Adi tALA. A.S.Krishnamurti & Shanta Radhakrishnan.
P: bhajana sEyavE O manasA bhajana sEyavE rAdhA lOluni parama dayALuni
A: bhavarOga bhESajamaina bhakta paripAluni pankajAkSuni parama pavitruni
C: gpAla bAluni gOdAnAthuni guru sanjIvAmrta rasikuni bhakti bhAvarAga layamu gUrcijnAna maNTapam tannil. rAgA: kalyANi. Adi tALA. Parvati Ammal.
P: jnAna maNTapam tannil jnAnAnada rUpiyai dhyAnam seivOm vArum nAdasvarUpa
A: jnAnOpadEsham seidu jnyAlattuyiraik-kArppAL tAnE tAnAi viLangum sadguruvAga nirppAL
C: vAnattu mazhai pOl vADum bhaktagaLaik-kArppAL kanal jalam pOL kANum ivvulagenbAn
mOnattirundu nIyum mukti aDaiyenbAL tEnAi soriyum divya sadguru upadEshanAda sudhArasa. rAgA: kAmavardhani. rUpaka tALA. composer not known.
P: nAda sudhArasa rasikE mAm pAhi mahA tripurasundari pAhi
A: vEda purANa nAda sudhAtmikE bhakta janArcita gIta guNAlayE
C: rAkendu sundara manda hasitE karuNAjaladhE kanakAdrivAsE
gIta vAdya (san) rasikapriyE harihara pUritE manda hasitEunnAlE enna Agum. rAgA: asAvEri. cApu tALA. Desiya Vinayakam Pillai.
P: unnAlE enna Agum Ezhai manida unnAlE enna Agum
A: nannArppUTTi oru nAyakan ATTi allAl tannAlE ADum pAvai dharaNiyil engumuNDO
C: ellAm iyaTrudarkku vallAn em maraikkumE sollAl aLavaruttu sollarkkariya pirAn
nallArkkum pollArkkum naDu ninru naTam seyum allArum kaNDanavan aruLaip-perAdirundAlvarai illAmal. rAgA: AbhEri. / cApu tALA. Kovai Subri.
P: varai illAmal aruLai vAri vazhangiDuvAn tirai kaDark-karaiyOram uraivOn aDiyArkku
A: kurai tam adai eDuttu kUrit-tannai aDuttu tiruccendUr vandu darishittiDuvOrkku
C: aDuttaDuttu OyAdu alai pAivadaip-pOl aDuttaDuttu OyAdu aDi tozha varuvOrkku
koDaikkaram OyAdu koDuttiDa sOrAdOn paDai vIDugaL Aru paDaittiTTa pErALan -
To add to the above message, the lyrics in my file are separated by 4 spaces between each lyrirc. Thanks.
-
You said:
the lyrics in my file are separated by 4 spaces between each lyrirc
You also said:
The next lyric starts after 4 blank lines, the next after another 4 lines and so on
These are different things.
I think I know what you mean, but again, why should we guess on this point.
You would have cleared up the confusion on this if you would have followed the Template for Search/Replace Questions that you were linked to.