How to replace string/text in multiple files using sed

by Eddy on

How to replace string/text in multiple files using sed

The streamline editor (sed) is very useful command for searching and replacing string/texts in multiple files As an example i am going to show you how i have used sed on my Linux web server. I have hundreds of file under a linux directory where i want to search and replace word mysql with mysql in single file intro.html using sed editor

$ sed -i ‘s/mssql/mysql/g’ intro.html

In the above command

sed -i is used to for editing the file

-s is used for subsituite the following text/word

-mssql is the word to be replaced by

-myssql is what you would like replace

-g is used for global search, looking for occurrence of text in all the lines in file

To replace word mssql with mysql in multiple files using sed editor run sed like this :

$ sed -i ‘s/mssql/mysql/g’ *.html

In Linux and UNIX sed command is available with default installation, However if you are a Micsrosoft Windows user , you can still harness power of sed by installing GNU utilities for Win32

News Tags:

Leave a Comment

Previous post:

Next post: