Editing (deleting) non-contiguous lines
-
Hello All,
New here but have been using Notepad++ for a few years.
I frequently run into this problem and I am sure there is a way to do it but after searching the forums came up empty (might not have been using the correct search criterion though).
I have a line with text I want to delete. Below it is another line I want to keep. This pattern continues for forty or fifty lines typically.
Is there a way to just select the unwanted lines, delete them and also remove the carriage returns?Ex. of original
Delete this line
Keep this line
Delete this line
Keep this line
(repeat)Desired outcome of edit
Keep this line
Keep this line
(repeat)Thanks for reading!!
Moe -
@Moe-Star
er “incorrect ctiteion” -
You appear to want to delete the “odd numbered” lines and keep the “even numbered” lines.
If so,
- FIND =
(?-s)^.*\R(.*$)
REPLACE =$1
☑ WRAP AROUND
SEARCH MODE = Regular Expression
REPLACE ALL
before
odd delete me even keep me odd delete this one too even keep also odd even odd evenafter
even keep me even keep also even even - FIND =
-
Wow! Thanks for the speedy reply.
I am sorry to mislead you but I am not a programmer so I am not sure exactly where I should be putting these commands (nor if there are variables I need to substitute).
I was trying to the the Find command Replace tab. Is that the correct place to use these commands?
Thanks again and sorry for the noobish questions.
Moe -
@Moe-Star said in Editing (deleting) non-contiguous lines:
I was trying to the the Find command Replace tab. Is that the correct place to use these commands?
As that is the only place these controls Peter cited are found:
- FIND
- REPLACE
- WRAP AROUND
- SEARCH MODE
- REPLACE ALL
You’ve really already answered a question you didn’t need to ask.
-
@Moe-Star
Yes,Search->Find...from the main menu, then go to theReplacetab, then but Peter’sFINDin theFind what...box, and Peter’sREPLACEin theReplace with:box.I generally just use
Ctrl+Fto open the find form, andCtrl+Hto open the find/replace form, but you may have different keybindings. -
I understood @Moe-Star’s question to be to find some keyword or anchor and to then start deleting every other line. The ending condition is the vague “This pattern continues for forty or fifty lines typically.”
FIND = (?-s)^.\R(.$)
REPLACE = $1works if someone is willing to copy/paste the forty or fifty lines typically into a new tab, run the search/replace/all which removes all of the odd numbered lines, and to copy/paste the results back.
I often I do exactly that as I don’t want to bother with figuring and testing out a regular expression that makes changes to a section of text while also not affecting the file above or below that section.
@Moe-Star, another way I often deal with this is to first insert what I call tags and then my set up my search/replace to only work on those lines that are tagged. For example, I have a file with many lines of text. I first do a search for
^_to make sure there are no lines that start with_. If^_already exists then I pick another tag, maybe_del_. The tag can be any pattern that you like. I like using_plus letters/digits for tags as I can double click a tag and all of that tag gets selected and visible in Notepad++.I then start adding a leading
_tag on those lines I will want to do a bulk search/replace operation on.Here’s something that may help you. Set up a set of lines with
_on every other line and then then load that into the copy/paste buffer as a column selection. You can then pick a spot in your file and paste will insert a_in front of every other line. If you do something by accident thenCtrl-Zundo quietly and quickly removes the_you just added._ _ _ _I usually use the keyboard and so column selections are created by holding the
Shift+Altkeys down while using up or down arrow plus one right or left arrow to select the_characters. You can do the same withAlt(orShift+Alt) and then dragging the mouse.Once I’m done with tagging the search replace becomes easy
Search:^_whatever I want
Replace:whatever I wantTo delete or mark the tagged lines I search for
^_.*\Rand replace with nothing. -
Wow again!
Great group and very helpful people!
I will give it a go again with these tips.
Thanks a bunch.