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 replace command which simple search text files to replace string and create 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 string in text files.

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

Beginning and End Of File

We can specify beginning and end of file with 

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

Sed Command

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


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

Perl Old Friend

We can accomplish replacement with Perl just like below

LEARN MORE  What is Microsoft Powershell ? How Can I Automate Tasks?

Leave a Reply

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

Enjoy this blog? Please spread the word :)