Notepad++ Question

amigan_99
amigan_99 used Ask the Experts™
on
Is there any way to search for all instances of a string in notepad++ and delete the whole line
on which the string is found?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Engineer
Commented:
I don't think you can do it with one search-replace step.

Try this....

Open up the search-replace, choose mode regex and search for:
^.*(string).*$ and let the replacement be \1 (this is the string that marks the lines you don't want). This will leave the lines with only the unwanted string and nothing else.

Then switch to the extended search and search for \r\nstring and leave the replacement blank. This will delete the lines with only the unwanted string in it.
amigan_99Network Engineer

Author

Commented:
Genius. That is sooo helpful for dealing with diff output from PAN firewalls. Thanks! I will post the screen shots for future travelers.
Top Expert 2015

Commented:
Aren't we supposed to employ quotations when copying and pasting from another source as per EE rule?

https://superuser.com/questions/237515/notepad-regexp-to-find-all-lines-which-contain-a-specific-string
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

amigan_99Network Engineer

Author

Commented:
This worked very well. Here are some screen shots for future travelers.
ScrnGrab1381-170519-11.22.jpg
ScrnGrab1382-170519-11.23.jpg
amigan_99Network Engineer

Author

Commented:
@Wayne88 - uh oh. What rule have I broken now?
Bill PrewTest your restores, not your backups...
Top Expert 2016

Commented:
Just for posterity, you can do it all in one shot.  Here is a sample Replace dialog to remove all lines that are just ABCDEF.  Notice we include a carriage return line feed before and after this, and replace with just a single carriage return line feed.

sshot-200.png

»bp
Top Expert 2015

Commented:
No that was for Scott C when copying and pasting solutions word for word from another source we are supposed to cite it.
amigan_99Network Engineer

Author

Commented:
Thanks for the step saver Wayne. This is very practical for dealing with PAN differ to create change control docs.
Top Expert 2015

Commented:
No problem and glad you found a solution to your question.  Cheers!
Scott CSenior Engineer

Commented:
Sorry...was in a hurry and missed doing that.  Thanks for catching that.
Top Expert 2015

Commented:
No problem, Scotty is one of our most active helpers.  :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial