• Login
Community
  • Login

move lines containing specific words to a specific position

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
5 Posts 2 Posters 146 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R
    Rockberto Manenti
    last edited by Feb 17, 2025, 9:44 AM

    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

    A 1 Reply Last reply Feb 17, 2025, 11:48 AM Reply Quote 0
    • A
      Alan Kilborn @Rockberto Manenti
      last edited by Feb 17, 2025, 11:48 AM

      @Rockberto-Manenti

      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 with DATE.

      If DATE always appears before GENRE 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.

      R 1 Reply Last reply Feb 17, 2025, 12:06 PM Reply Quote 2
      • R
        Rockberto Manenti @Alan Kilborn
        last edited by Rockberto Manenti Feb 17, 2025, 12:08 PM Feb 17, 2025, 12:06 PM

        @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!

        A 1 Reply Last reply Feb 17, 2025, 12:11 PM Reply Quote 2
        • A
          Alan Kilborn @Rockberto Manenti
          last edited by Feb 17, 2025, 12:11 PM

          @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. :-)

          R 1 Reply Last reply Feb 17, 2025, 1:30 PM Reply Quote 2
          • R
            Rockberto Manenti @Alan Kilborn
            last edited by Feb 17, 2025, 1:30 PM

            @Alan-Kilborn

            thanx again. I solved with a macro! Thanks again for the idea and initial regex!

            1 Reply Last reply Reply Quote 3
            1 out of 5
            • First post
              1/5
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors