1

I have to replace words in files/folders with replace-words length (234,206 words).

Notepad++ does not allow replace-word-count more than 2,047 words. TextCrawler 3 does not allow replace-word-count more than 29,999 words.

Just simple replacement. No regex special needed.
Files/Subfolders in Folder option is needed.

1
1

You should be able to do this with a simple python script, something like:

import os

# Assuming that the replacement words are in a plain text file with
# colon separating the original & new words and one pair per line.
SEP = ":"
REPLACE_SOURCE = "/full/path/to/replacement/list.txt"
START_DIR = "."
with open(REPLACE_SOURCE) as infile:
    replacement_pairs = [line.strip().split(SEP) for line in infile]

for (root, dirs, files) in os.walk(START_DIR):
    print("Working in", root)
    for fname in files:
        fullpath = os.path.abspath(os.path.join(root, fname)
        if fname.lower.endswith('.txt') and fullpaht != REPLACE_SOURCE:
            print("\tProcessing", fname)
            intext = open(fullpath).read()
            for orig, repl in replacement_pairs:
                intext = intext.replace(orig, repl)
            # You may wish to consider renaming the original file here!
            with open(fullpath, 'wt') as outfile:
                outile.write(intext)

Warning the above will replace the contents of all .txt files under the current directory.

This should cope nicely unless some of the files are too big for the content to fit into the available memory.

Python is free, cross platform and open source.

2
  • Thanks you @Steve Baarnes. Does it include *.txt in subfolders? – South Korea Jun 4 '17 at 7:43
  • The above script would perform replace on every *.txt file in all sub-directories below the current directory, (other than the replace source file, (if it happens to be in the current directory or a nested directory). – Steve Barnes Jun 4 '17 at 11:27
0

So you have this massive plain text document and you are going to search/replace something that has hundreds of thousands of occurances.

Exit out of Notepad and just run sed on it. https://www.gnu.org/software/sed/manual/sed.txt

Built in with OS X and Linux, there are win32 ports/builds, should be in the linux-inside-windows thing, etc.

1
  • I read the question as there being 234,206 pairs of words that all the originals have to be replaced so any one file might have only one word changed or several thousand in each of however many files there are in the directory & sub-directories - this would mean calling sed recursively a total of 234,206 times so might take a while. – Steve Barnes Jun 4 '17 at 11:31

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.