Community
    • Login

    move lines containing specific words to a specific position

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 2 Posters 130 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.
    • Rockberto ManentiR
      Rockberto Manenti
      last edited by

      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

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Rockberto Manenti
        last edited by

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

        Rockberto ManentiR 1 Reply Last reply Reply Quote 2
        • Rockberto ManentiR
          Rockberto Manenti @Alan Kilborn
          last edited by Rockberto Manenti

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

          Alan KilbornA 1 Reply Last reply Reply Quote 2
          • Alan KilbornA
            Alan Kilborn @Rockberto Manenti
            last edited by

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

            Rockberto ManentiR 1 Reply Last reply Reply Quote 2
            • Rockberto ManentiR
              Rockberto Manenti @Alan Kilborn
              last edited by

              @Alan-Kilborn

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

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