Deleting all even-numbered lines an something more?
-
@fairbanksbiz said in Deleting all even-numbered lines an something more?:
I’d like to “connect” all the rest of the remaining text as if it was all on a single line.
The Edit menu’s Line Operations submenu has a choice for joining lines together. Maybe it meets your need.
-
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
-
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.
-
@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… -
@alan-kilborn huh? I swear to God it doesn’t. I’ll do further tries anyway.
-
@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-kilborn I just made another try with the command you suggested and yes, it appeared it worked this time around.
-
@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:
Any suggestion?
-
I think I solved my problem with the following strategy:
Find: \r\n.+\r\n
Replace with: one empty pace
Search mode: Regular expressionI 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.
-
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
-
This post is deleted! -
@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! :-) -
@peterjones said in Deleting all even-numbered lines an something more?:
Because your new data doesn’t match what you showed originally.
Amen!
-
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.
-
@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?
-
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.
-
@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.
-
@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.