<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Search-and-Replace on despatches</title><link>https://icle.es/tags/search-and-replace/</link><description>Recent content in Search-and-Replace on despatches</description><generator>Hugo</generator><language>en</language><lastBuildDate>Fri, 20 Jun 2025 09:25:00 +0100</lastBuildDate><atom:link href="https://icle.es/tags/search-and-replace/index.xml" rel="self" type="application/rss+xml"/><item><title>Linux bulk search and replace</title><link>https://icle.es/2010/04/21/linux-bulk-search-and-replace/</link><pubDate>Wed, 21 Apr 2010 13:47:26 +0000</pubDate><guid>https://icle.es/2010/04/21/linux-bulk-search-and-replace/</guid><description>&lt;p>Doing a bulk search and replace across a set of files is actually surprisingly
easy. sed is the key. It has a flag - i that will modify the files passed to it
in-place.&lt;/p>
```bash
$ sed -e 's/TextToFind/Replacement/' -i file1 file2 file3
```
&lt;p>Tie this power with either grep &lt;code>-l&lt;/code>. (Thanks to Steve for pointing out a
mistake in the following, now corrected)&lt;/p>
```bash
$ grep -l TextToFind * |xargs sed -e 's/TextToFind/Replacement/' -i
```
&lt;p>or find&lt;/p></description><content:encoded><![CDATA[<p>Doing a bulk search and replace across a set of files is actually surprisingly
easy. sed is the key. It has a flag - i that will modify the files passed to it
in-place.</p>
```bash
$ sed -e 's/TextToFind/Replacement/' -i file1 file2 file3
```
<p>Tie this power with either grep <code>-l</code>. (Thanks to Steve for pointing out a
mistake in the following, now corrected)</p>
```bash
$ grep -l TextToFind * |xargs sed -e 's/TextToFind/Replacement/' -i
```
<p>or find</p>
```bash
$ find . -exec sed -e 's/TextToFind/Replacement' -i {} ;
```
<p>If there are multiple changes you want to make, just put them all into a file
and pass it in via the -f flag.</p>
<p>file: replacements.patterns</p>
```sed
s/TextToFind1/Replacement1/
s/TextToFind2/Replacement2/
s/TextToFind3/Replacement3/
```
<p>and the command, using find to iterate through all files in the current
directory and subdirectories.</p>
```bash
find . -exec sed -f replacements.patterns -i {} ;
```
<p>et voila - hope it helps.</p>
]]></content:encoded></item></channel></rss>