Bash replacing string inside text files using SED command line Ubuntu

This is mostly happen when we have many configuration or text files inside our Ubuntu / servers. For example , i have 5 nginx virtualhost files. For some reason, i need to change my sites to run NGINX on port 84. So i need to change

1
listen 80;

into

1
listen 84;

in each virtualhost files.

The fast way to do it is by using SED. The pattern is :

1
sed -i 's/<search-string>/<replace-string>/ your-files'

Here are example :

1
sudo sed -i 's/listen   80;/listen   84;/' *

Now all files which contain listen 80; will replaced with listen 84;. Easy right ? :D

Anda sudah membaca sampai disini? Mantap! Follow twitter saya.

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>