Community
    • Login

    I want every 2 lines to have specific text added at the end of each of them.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 3 Posters 551 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.
    • GabrielPG
      GabrielP
      last edited by

      for example lets say i have the following text

      line1
      line2
      line3
      line4
      line5
      line6
      

      I want this text to become

      line1.mp4
      line2.srt
      line3.mp4
      line4.srt
      line5.mp4
      line6.srt
      

      ive searched for a bit and couldnt fine a solution to do this specifically, thanks

      PeterJonesP mkupperM 2 Replies Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @GabrielP
        last edited by PeterJones

        @GabrielP said in I want every 2 lines to have specific text added at the end of each of them.:

        ive searched for a bit and couldnt fine a solution to do this specifically

        Specifically, no, because no one has your exact text. Expecting any search on the internet to give you exactly what you want without you having to interpret it for your specific circumstance is a bit optoomuchstic.

        But this is the kind of situation that the REPLACE FROM A SMALL LIST OF VALUES section of our FAQ was meant to cover: in general, it shows you how to replace matched text with a small list of values. In your specific situation, you would want to search for $ (match at the end of the line, so the replacement is just appended without deleting anything), and your list of replacements would be ['.mp4', '.srt'].

        GabrielPG 1 Reply Last reply Reply Quote 3
        • mkupperM
          mkupper @GabrielP
          last edited by

          @GabrielP I would use a search/replace for lines ending with odd/even values. It’s low tech but is safe and works in a predictable and understandable way.

          Search: ([02468])$
          Replace: \1.srt
          and
          Search: ([13579])$
          Replace: \1.mp4

          The above makes the assumption that your data has numbers at the ends of them. If your actual data is more like.

          safe
          and
          works
          in
          a
          predictable
          and
          understandable
          way
          

          then I still like do do it in several safe passes. For example - this will join pairs of lines using ~ as the separator.
          Search: ^(.+)\R(.+)$
          Replace: \1~\2
          I do a search/replace all and see that the results look good. The last line is just the word way meaning it’s not part of a pair. With real data I would think about how that should be dealt with but for now, I don’t care.

          Once the data looks safe it’s easy to then
          Search: $
          Replace: .srt
          and
          Search: ~
          Replace: .mp4\r\n

          The ~ can be any character as long as it’s something that is not used in your file. You can use anything such as \t tab, \x00 NUL, etc.

          GabrielPG 1 Reply Last reply Reply Quote 1
          • GabrielPG
            GabrielP @PeterJones
            last edited by

            @PeterJones is there no way to add text to odd lines and then another text to even lines?

            right now im trying this,

            (?-s)^(.+\R)(.+\R?)
            \1.mp4 & \2.srt

            455b977d-ba26-487b-b542-d40031f79a22-image.png
            which i saw here

            but unfortunately my text goes from this
            (im replacing ONLY the first 2 lines btw, to show you that it ends up affecting the 3rd line too)

            1 - Aula de apresentação
            1 - Aula de apresentação
            1 - Políticas Públicas: Definições e Componentes
            1 - Políticas Públicas: Definições e Componentes
            

            to this

            1 - Aula de apresentação
            .mp4 & 1 - Aula de apresentação
            .srt1 - Políticas Públicas: Definições e Componentes
            1 - Políticas Públicas: Definições e Componentes
            

            when if im only replacing the first 2 lines, it just want it to become this

            1 - Aula de apresentação.mp4
            1 - Aula de apresentação.srt
            1 - Políticas Públicas: Definições e Componentes
            1 - Políticas Públicas: Definições e Componentes
            
            PeterJonesP 1 Reply Last reply Reply Quote 0
            • GabrielPG
              GabrielP @mkupper
              last edited by

              @mkupper this worked great, thanks!
              9cdd4325-e8f6-40fa-9a85-d684b18cb503-image.png

              1 Reply Last reply Reply Quote 1
              • PeterJonesP
                PeterJones @GabrielP
                last edited by

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors