How to find and replace line(s) in multiple files using Notepad++?

10

5

I have been messing with notepad++ for a bit now and am confused as to how to go about doing this:

I have a line in multiple files (Within a root directory) that I am searching for. Example:

Brittany (File 1)
     PeopleSleptWith 2
Tiffany (File 2)
     PeopleSleptWith 4
Bonqueesh (File 3)
     PeopleSleptWith 3456
.
.
.

My goal is to replace all of the PeopleSleptWith lines with a constant (I.E. PeopleSleptWith 7) but when I search and replace in multiple files, it does not remove complete line, which results in:

Brittany (File 1)
     PeopleSleptWith 7 2
Tiffany (File 2)
     PeopleSleptWith 7 4
Bonqueesh (File 3)
     PeopleSleptWith 7 3456

When in reality I want:

Brittany (File 1)
     PeopleSleptWith 7
Tiffany (File 2)
     PeopleSleptWith 7
Bonqueesh (File 3)
     PeopleSleptWith 7

So how do i go on about finding a string, removing everything within that line, and replacing it with another string?

Sh3perd

Posted 2015-11-22T03:45:23.247

Reputation: 103

Answers

19

Using Notepad++ to find a string on a line in a file, and replace that entire line with the match with another string

Instructions

Open Notepad++ and press Ctrl+F and then from the Find in Files tab options.

Now you'll...

  1. Put the string in the regex format of the Find What: ^.*(PeopleSleptWith).*$

    • The string will go between the "()" parenthesis just as shown above in #1
  2. Put the 5 spaces and then the Replace with: PeopleSleptWith 7 string

  3. Put the Filters: as *.* or *.txt or whatever you are replacing file type wise
  4. Put the Directory: where you want it to be (the root folder)
  5. Check the Regular expression option
  6. Select Replace in Files
  7. Check the file(s) and all should be correct now

    enter image description here

Pimp Juice IT

Posted 2015-11-22T03:45:23.247

Reputation: 29 425

sorry about that. I didn't even see it at first. Thank you! – Sh3perd – 2017-02-06T20:15:46.203