How To Replace A Text Exists In Many Files? – POFTUT

How To Replace A Text Exists In Many Files?

Linux provides a lot of tools to ease system administrators work. One of them is to replace command which simple search text files to replace string and create a new text file. Replace command comes with MySQL Server packages. IF MySQL is not installed we can not use replace command.

Replace Command

We can use replace command to change a string in text files.

  • BEFORE is the string we search for
  • AFTER is the new string
  • < YOURCOMMAND is our original text file
  • > NEWTEXTFILEis newly created text file with replace string

Beginning and End Of File

We can specify the beginning and end of the file with

  • Replace string Before which is at the beginning of the line

Sed Command

An alternative to replace command is sed. Sed is generally installed by default most of the distributions. So we can replace sed with replace.

OR

In this example replace done in place so the new file wouldn’t be created.

Perl Old Friend

We can accomplish replacement with Perl just like below. In the following example, we will change the text Before with the After text.

LEARN MORE  Linux usermod Command Tutorial With Examples

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)