sed Replace String in File

In this post, we will see how to replace String in file using sed in linux.

Problem

How to find and replace "Text1" with "Text2" using sed command in linux.

Solution

Sed stands for stream editor.It reads the file and modifies the file as provided by list of sed command.By default, input is written on the screen but you can update the file as well using -i option.

Here is simple command to replace string in file.

sed -i -e ‘s/old-string/new-string/g’ sample.txt

Was this post helpful?

Leave a Reply

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