How to find and replace text in multiple files from the terminal

Search and Replace text can be a simple task using the text editors more basic. But what happens when you need to do that same task in multiple files at the same time?

Well, things get complicated there ... or not so much.


In the following example, we will use sed to replace all occurrences of the word "mongo" with the word "aurelio" in all files that have the extension .txt and that are in the / home / user / myfolder / folder.

find / home / user / myfolder / -name * .txt -exec sed -i "s / mongo / aurelio / g" {} \;

That easy…

Before finishing, it is worth mentioning that some text editors allow this operation to be carried out using a graphical interface. Among others, it is worth highlighting Jedit, Geany, Regexxer, etc.


Add as preferred source in Google