Community
    • Login

    Deleting all even-numbered lines an something more?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    20 Posts 4 Posters 5.5k 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.
    • Alan KilbornA
      Alan Kilborn @FairbanksBiz
      last edited by

      @fairbanksbiz

      If you need more help of this type, perhaps best to read and follow this: https://community.notepad-plus-plus.org/topic/22022/faq-desk-template-for-search-replace-questions

      FairbanksBizF 1 Reply Last reply Reply Quote 1
      • FairbanksBizF
        FairbanksBiz @Alan Kilborn
        last edited by

        The “join lines” thing in the Edit menu has worked just nice. The “^\d\d:\d\d\R” has not. It works only a bit, for a few even-numbered lines, but others do not seem to get deleted. Other attempts deleted them all but added “1:” before each even-numbered line.

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

          @fairbanksbiz said in Deleting all even-numbered lines an something more?:

          The “^\d\d:\d\d\R” has not. It works only a bit, for a few even-numbered lines, but others do not seem to get deleted. Other attempts deleted them all but added “1:” before each even-numbered line.

          It works on the data you showed, as near as we can tell from a screenshot.
          If you didn’t represent your data appropriately, or follow the instructions on posting, well…

          FairbanksBizF 4 Replies Last reply Reply Quote 1
          • FairbanksBizF
            FairbanksBiz @Alan Kilborn
            last edited by FairbanksBiz

            @alan-kilborn huh? I swear to God it doesn’t. I’ll do further tries anyway.

            1 Reply Last reply Reply Quote 0
            • FairbanksBizF
              FairbanksBiz @Alan Kilborn
              last edited by FairbanksBiz

              @alan-kilborn By the way, are you sure it shouldn’t be “^\d\d:\d\d\r” instead of “^\d\d:\d\d\R”?

              Alan KilbornA 1 Reply Last reply Reply Quote 0
              • FairbanksBizF
                FairbanksBiz @Alan Kilborn
                last edited by

                @alan-kilborn I just made another try with the command you suggested and yes, it appeared it worked this time around.

                1 Reply Last reply Reply Quote 0
                • FairbanksBizF
                  FairbanksBiz @Alan Kilborn
                  last edited by

                  @alan-kilborn Sometimes it works, sometimes it doesn’t. Why?

                  For instance, I’m trying to delete the even-numbered lines in another document, and it’s not working.

                  See for yourself:

                  uiyiu7tititygine.png

                  Any suggestion?

                  FairbanksBizF PeterJonesP 2 Replies Last reply Reply Quote 0
                  • FairbanksBizF
                    FairbanksBiz @FairbanksBiz
                    last edited by

                    I think I solved my problem with the following strategy:

                    Find: \r\n.+\r\n
                    Replace with: one empty pace
                    Search mode: Regular expression

                    I works every time and I don’t even have to act upon the “join lines” thing because it’s built-in in the command.

                    Nevertheless, thank you for your help.

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

                      @fairbanksbiz ,

                      and it’s not working

                      Because your new data doesn’t match what you showed originally.

                      A regex that matches two digits followed by a colon followed by two digits and a newline cannot possibly match a didit followed by colon and two digits then colon and two digits, then a newline.

                      ^(\d+:)?\d{1,2}:\d\d\R

                      This will match any timestamp with 1 or more optional hour digits, one or two digits for the minutes, and two digits for the seconds. If you have timestamps that don’t match that pattern, it’s because you didn’t show us enough example data, not because we are failing to give you accurate regex for the examples you provide.

                      are you sure it shouldn’t be…

                      Nope. \R means any newline sequence (CR, LF, or CRLF), whereas \r matches only a single CR, which would not work unless you have old Mac line endings, which is highly unlikely.

                      And you never took Alan’s repeated advice to use the regex question template, which would have allowed us to copy/paste the text, rather than making us read an image and type the text ourselves.

                      ----

                      Useful References

                      • Please Read Before Posting
                      • Template for Search/Replace Questions
                      • FAQ: Where to find regular expressions (regex) documentation
                      • Notepad++ Online User Manual: Searching/Regex
                      Alan KilbornA FairbanksBizF 2 Replies Last reply Reply Quote 0
                      • PeterJonesP
                        PeterJones @FairbanksBiz
                        last edited by

                        This post is deleted!
                        1 Reply Last reply Reply Quote 0
                        • Alan KilbornA
                          Alan Kilborn @FairbanksBiz
                          last edited by

                          @fairbanksbiz said in Deleting all even-numbered lines an something more?:

                          are you sure it shouldn’t be “^\d\d:\d\d\r” instead of “^\d\d:\d\d\R”?

                          Yes, I’m sure.
                          If you don’t know what you’re doing, don’t doubt what is supplied! :-)

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

                            @peterjones said in Deleting all even-numbered lines an something more?:

                            Because your new data doesn’t match what you showed originally.

                            Amen!

                            FairbanksBizF 1 Reply Last reply Reply Quote 0
                            • FairbanksBizF
                              FairbanksBiz @Alan Kilborn
                              last edited by

                              Alan and Peter, it goes without saying that I’m not a whiz at this, I’m trying my best to provide explanations and to follow your advice.

                              1 Reply Last reply Reply Quote 0
                              • FairbanksBizF
                                FairbanksBiz @PeterJones
                                last edited by

                                @peterjones Should I use the command ^(\d+:)?\d{1,2}:\d\d\R to get rid of those pesky timestamps in the even-numbered lines then? Also, is there a way to directly join the remaining lines without having to go through the Edit menu? By the way, doesn’t the command that I’ve come up with, \r\n.+\r\n, with one empty space as the replacement of choice, do just that?

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

                                  @fairbanksbiz ,

                                  Your solution assumes it’s always every other line, and that you didn’t start your search on the wrong line. Our solutions specifically target timestamps, and nothing else.

                                  If you add a \R before the caret, and change the replacement to a single space, it might do it all in one.

                                  In the end, it’s your data, and you are responsible to make sure you don’t lose important text: chose whatever works for you with that understanding.

                                  1 Reply Last reply Reply Quote 3
                                  • Juan Flavio OrozcoJ
                                    Juan Flavio Orozco @FairbanksBiz
                                    last edited by

                                    @fairbanksbiz It would not complicate me so much, I would place myself at the beginning of the first line with the time, I would start recording a “macro”. Already recording the macro; holding the “shift” key you would press the “end” key and then (without releasing “shift”) once the “right” (→) key, release “shift” and press “Delete”.

                                    So the time line disappears and leaves you at the beginning of the text line, so you press the “down” (↓) key. This puts you at the start of the time line, so you stop the macro recording.

                                    The second part is to name the macro, and in “Run macro multiple times…” you select the macro you recorded, select the option to “Run to end of file” and that’s it, it will go row by row doing what you want. .

                                    No me complicaría tanto, me colocaría al inicio de la primer línea con la hora, iniciaría la grabación de una “macro”. Ya grabando la macro; sosteniendo la tecla “shif” presionaría la techa “fin” y un luego (sin soltar “shif”) una vez la tecla “derecha” (→), soltas “shif” y presionas “Delete”.

                                    Así desaparece la linea de la hora y te deja al inicio de la línea de texto, entonces presionas la tecla “abajo” (↓). Esto te coloca en el inicio de la línea con hora, entonces paras la grabación de la macro.

                                    La segunda parte es pnerle nombre a la macro, y en “Ejecutar macro múltiples veces…” seleccionas la macro que grabaste, seleccionas la opción de “Ejecutar hasta el final del archivo” y listo, irá fila por fila haciendo lo que quieres.

                                    Alan KilbornA 1 Reply Last reply Reply Quote 0
                                    • Alan KilbornA
                                      Alan Kilborn @Juan Flavio Orozco
                                      last edited by

                                      @juan-flavio-orozco said in Deleting all even-numbered lines an something more?:

                                      It would not complicate me so much, I would place myself at the beginning of the first line with the time, I would start recording a “macro”. Already recording the macro; holding the “shift” key you would press the “end” key and then (without releasing “shift”) once the “right” (→) key, release “shift” and press “Delete”.

                                      So just a note on this technique:

                                      It doesn’t “protect” your data. If you accidentally start the macro on the wrong line, you will operate (delete) the wrong data.

                                      With the replacement approach using regular expressions, only data that matches the proper pattern will be removed.

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