16

I have the following text in Notepad++.

192.168.0.1 37 ms N/A
192.168.0.2 Dead N/S
192.168.0.3 Dead N/S
192.168.0.100 37 ms N/A

How do I do a find and replace that matches "Dead" and eliminates the line with output like the following?

192.168.0.1 37 ms N/A
192.168.0.100 37 ms N/A

I have tried to use the regular expression ^.*Dead.*$ that does remove the lines, but it doesn't delete the empty spaces.

1
  • Unfortunately it is not the line with Dead that is the problem it is the endline at the end of the previous line before Dead. I am uncertain if you can use a regex to find a line and the endline before it. – SC Ghost Jun 2 '11 at 21:25
17

Go to the search then to the Mark tab, enter "Dead", check "mark line" and click "Find all". It results in bookmarks for all those lines.

In the search menu there is a point "delete bookmarked lines"

2
  • 1
    I like this answer! – vsync Jul 1 '11 at 19:51
  • In 7.7.1 Version. After pressing Ctr+f find 4th tab Mark. Select Bookmark line option, enter your desired string and click mark all. Now in document F2 can be used to navigate bookmarks for forward and Shift+F2 for backwards. Ctrl+F2 to toggle bookmarks. Now Find 3rd Search menu top left. Find Bookmark option at bottom. Use Remove Bookmarked Lines option to remove all lines. – Ramaprakasha Oct 25 '19 at 20:34
16

You can use two steps:

Use regex to replace matches for ^.*Dead.*$ with markedfordel

Then in extended mode, for matches of markedfordel\r\n replace with empty

Screenshot:

enter image description here

1
  • Good thing you were here, I would have blindly answered saying it could be done with only a regex before actually thinking about it. – MBraedley Jun 3 '11 at 0:29
1

Combine/enhance/replace your regex with the solutions here: Delete blank lines from a text file

0

Try a Regex replace in Notepad++ with:

(.*)Dead(.*)

That'll remove the lines for you.

0

You can use your first step to blank the lines that contain "Dead" in them, and then what I usually do is use one of the plugins typically included with Notepad++ to remove blank lines. To do that, I press Ctrl+A to highlight the entire document, then go to the TextFX menu (for the TextFX plugin), go to TextFX Edit, and then select Delete Blank Lines (about halfway down the menu). That will, as it said, remove all blank lines in the highlighted region.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy