C
C
Cooler22021-04-20 10:28:26
Text Processing Automation
Cooler2, 2021-04-20 10:28:26

How to execute a set of regular expressions on multiple files?

There is a set of regular expressions (~100 pieces) to perform a replacement in the text. You need to perform these replacements in all files matching the given masks. What is the easiest way to do this?

This is the task of project migration: the API has changed and you need to replace old calls with new ones in all project files. It is desirable so that any other user can use it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Romses Panagiotis, 2021-04-20
@romesses

The text editor is not specified and they have different capabilities.
Therefore (for me) the easiest way is to replace with a bunch of GNU tools: find (search for files by mask and start processes on them) + sed (actually, replaces the text of a file with a regular expression)
Before executing, test on single files and save the original version of the files.

find /path/to/project -type f -name "*.php" -exec sed -i 's/регулярка/новыйтекст/g' {} \;

But if there is a code editor that does the same, then there is no problem with that either.
Anticipating the question about the presence of GNU utilities in Windows, I give the link:
https://en.wikipedia.org/wiki/GnuWin32

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question