0

I am using Windows 7. I need to replace multiple occurences of multiple words in multiple text files.

For example, suppose there are 20 files. I have a list of words to find, and the words to replace them with. Suppose, The find list has words like "12345678", "ABCDEFGH", etc. The replace list has words like "76892", "A563", etc.

In each file, I need to replace each word in my find list with the word in the replace list. As you can see, there is no direct pattern in the find list and the replace list.

Instead of doing it manually one by one, is there a way to do it quickly, using some utility (should be free)? I can do it programmatically, but I am looking for an answer without writing any code. If there were a pattern between the Find list and the Replace list, I could have used Regular Expressions, but there is no pattern.

An example will be helpful. Even with TextPad's Find in Files feature, I dont think it is possible, as there is no pattern. I have searched multiple threads in this forum, but many answers either refer to writing a macro or a PowerShell utility or using Regular Expressions, etc. I hope this is not marked as Duplicate by the moderators.

Mokubai
  • 92,720
  • 1
    I can do it programmatically, but I am looking for an answer without writing any code - Can I ask why you're looking for this type of solution? – Dave May 17 '16 at 10:57
  • Its easier to use an already available utility rather than write code. On 2nd thoughts, I am open to using PowerShell, but I do not know it and learning curve will take time. If someone can just post the exact PowerShell script which can do the job, I can use it. – AllSolutions May 17 '16 at 11:06
  • Can PowerShell loop over all files in directory (there are no subdirectories)? Can it take inputs for the find-list and the replace-list which are stored in an external file (text file or excel file)? There is no need of Regular Expressions if it can read the find and replace list from an external source. – AllSolutions May 17 '16 at 11:07
  • 1
    Easiest way I could found is using Notepad++: there you can replace content of a list with Python script plug-in and also find and replace in files – Máté Juhász May 17 '16 at 11:16
  • Ah, but I am not familiar with Python. Secondly, specifiying all the find words and replace words inline in the regular expression (as shown in the link posted by you) may not be possible, as the list is BIG. – AllSolutions May 17 '16 at 11:23
  • The Python script posted in that link is pretty simple. I can use it even without understanding much of Python syntax. But how do I run this script from NotePad++, and how do I run it over multiple files? – AllSolutions May 17 '16 at 11:30
  • @AllSolutions, you said you can do it programmatically and now saying you can't?!? – Dave May 17 '16 at 11:32
  • @Dave, I can do it programmatically using C#. I do not know all the languages :) – AllSolutions May 17 '16 at 11:32
  • @Mate Juhasz, I have installed NotePad++ and the Python Script Plugin. How do I select the script in the Find in Files window, or else how do I run the script across multiple files in a folder? The script seems to run only on active file. – AllSolutions May 17 '16 at 11:52
  • just because I had some spare time and fun writing code, this is what a PS Script would look like for this case: get-childitem "C:\yourpath" -filter *.txt | % {(Get-Content $($_.FullName)) -replace "12345678","A563" | Set-Content } – SimonS May 17 '16 at 12:09
  • I will try this, but can you suggest what changes should be done in your code to read the find and replacement texts from an external file? As I said, I do not know Python. – AllSolutions May 17 '16 at 12:14

1 Answers1

1

It's quite simple using Notepad++. Suppose you have directories like below.

Folder
    Folder1
        FILE-1
    Folder2
        FILE-2
    Folder3
        FILE-3
    Folder4
        FILE-4`

If you want to replace a key 'text1' in all files with 'text2' then:

  1. Open Notepad++.
  2. Click on Open as workspace.
  3. Select main folder.
  4. Right-click on main folder and click Find in Files.
  5. Enter 'text1' in Find what. Enter 'text2' in Replace. Enter. in filter
  6. Click OK. All text occurrences will be replaced.
karel
  • 13,488
Brayan
  • 11