move lines containing specific words to a specific position
-
Hi to all. This question is similar to one I asked a while back, but with a few small differences.
On several text files I need to move lines that contain specific words, to a certain position.
In practice the lines that contain
REM GENRE
REM DATE
must go respectively to line 1 and line 2 of the text.
After REM GENRE and REM DATE there is some text that is variable from file to file.
Example:REM COMMENT “CUETools generated CUE sheet”
PERFORMER “Black Wings”
TITLE “Whispers Of Time”
REM DATE 2024
REM DISCNUMBER 1
REM TOTALDISCS 1
REM GENRE “Metal”
FILE “Black Wings - Whispers Of Time.flac” WAVE
TRACK 01 AUDIO
PERFORMER “Black Wings”
TITLE “Opening the Gates”
INDEX 01 00:00:00
TRACK 02 AUDIO
PERFORMER “Black Wings”it must become
REM GENRE “Metal”
REM DATE 2024
REM COMMENT “CUETools generated dummy CUE sheet”
PERFORMER “Black Wings”
TITLE “Whispers Of Time”
REM DISCNUMBER 1
REM TOTALDISCS 1
FILE “Black Wings - Whispers Of Time.flac” WAVE
TRACK 01 AUDIO
PERFORMER “Black Wings”
TITLE “Opening the Gates”
INDEX 01 00:00:00
TRACK 02 AUDIO
PERFORMER “Black Wings”Is there a way with some regex?
Thanks in advance -
Do it in 2 operations.
First, do:
- Find:
\A(?s-i)(.*?)^(REM GENRE (?-s).+?\R)
- Replace:
${2}${1}
Then, repeat the first replacement, replacing
GENRE
withDATE
.If
DATE
always appears beforeGENRE
in your files, it is possible (reasonable) to do it in one operation. It is also possible to do it in one operation if the ordering is random.But, as you were just asking for a solution with no more specifics, two operations suffice.
- Find:
-
@Alan-Kilborn
many thanks.
this regex works, but I have to apply it first on REM DATE and then on REM GENRE because otherwise if I do GENRE first and then DATE, the latter puts it as the first line.if it were possible to do it in a single operation it would be faster.
The two lines REM GENRE and REM DATE are not always in the same order but random
Many thanks! -
@Rockberto-Manenti said in move lines containing specific words to a specific position:
but I have to apply it first on REM DATE and then on REM GENRE because otherwise if I do GENRE first and then DATE, the latter puts it as the first line.
Yea, ok, that’s a small detail, so I didn’t pay much real attention to the actual one you wanted first. You got the idea. :-)
faster
Sure, could do a single regex, but it doesn’t excite me to formulate that for you. Someone else will, I’m sure. :-)
-
thanx again. I solved with a macro! Thanks again for the idea and initial regex!