Difference between revisions of "Sed"

From DevOps Notebook
(Created page with "== Search and replace string in single file == <pre> sudo sed -i -e "s/upload_max_filesize = \"500M\"/upload_max_filesize = \"1200M\"/g" /etc/php7.4/cli/php.ini </pre>")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Search and replace string in single file ==
 
== Search and replace string in single file ==
 
<pre>
 
<pre>
sudo sed -i -e "s/upload_max_filesize = \"500M\"/upload_max_filesize = \"1200M\"/g" /etc/php7.4/cli/php.ini
+
$ sudo sed -i -e "s/upload_max_filesize = \"500M\"/upload_max_filesize = \"1200M\"/g" /etc/php7.4/cli/php.ini
 +
</pre>
 +
 
 +
 
 +
== Search and replace string in multiple files recursively ==
 +
<pre>
 +
$ find /etc/httpd -type f -name '*.conf' -print0 |xargs -0 sed -i -e 's/192.168.1.2/192.168.1.5/g'
 
</pre>
 
</pre>

Latest revision as of 15:46, 5 May 2023

Search and replace string in single file

$ sudo sed -i -e "s/upload_max_filesize = \"500M\"/upload_max_filesize = \"1200M\"/g" /etc/php7.4/cli/php.ini


Search and replace string in multiple files recursively

$ find /etc/httpd -type f -name '*.conf' -print0 |xargs -0 sed -i -e 's/192.168.1.2/192.168.1.5/g'