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.
-
Maybe Swiss File Knife could do it– Angel Montes de OcaCommented Jun 3, 2017 at 17:53
2 Answers
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.
-
Thanks you @Steve Baarnes. Does it include *.txt in subfolders? Commented Jun 4, 2017 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). Commented Jun 4, 2017 at 11:27
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.
-
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. Commented Jun 4, 2017 at 11:31