I want to replace text in about 80.000 log files using a regex. I love the batch search and replace of VSCode. I was unable to do this with VSCode, because it did not seem to handle this amount of data well. Any suggestion how I could do this with VSCode? Are there suggestions for alternatives?
-
Notepad++ can handle any number of files and also has regex find-replace, or write a simple python script that uses a glob over the current directory – rioV8 Feb 18 '21 at 11:18
1 Answers
Instead of depending on a GUI-based tool, it might be easier to use a CLI tool for this.
If you're using Linux, or willing to install any of the tools like sed
and find
if you're on Windows, then it should be relatively simple.
You can use sed
which is a command line tool on all (or at least most) distributions of Linux, and can be installed on Windows.
Usage (for this use case):
sed -i s/{pattern}/{replacement}/g {file}
Use
sed
to replace the matched pattern with a replacement, using the global modifier to match all results, and the file to do the replacement and overwrite.
To target all files in a directory you can do:
find -type f -name "*.log" exec sed -i s/{pattern}/{replacement}/g {};
Find items recursively starting from the current directory where it's type is file, and it has a name ending with
.log
. Then usesed
to replace the pattern with the contents you want for each matched file.
You can find how to get tools like sed
and find
for Windows on the following question:
https://stackoverflow.com/a/127567/6277798

- 313
- 6
- 22