Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Jun 2 '11 at 22:33

This question came from our site for professional and enthusiast programmers.

    
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
add comment

5 Answers

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

share|improve this answer
    
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
add comment

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"

share|improve this answer
1  
I like this answer! –  vsync Jul 1 '11 at 19:51
add comment

Combine/enhance/replace your regex with the solutions here: http://superuser.com/questions/35233/delete-blank-lines-from-a-text-file

share|improve this answer
add comment

Try a Regex replace in Notepad++ with:

(.*)Dead(.*)

That'll remove the lines for you.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.