<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged sed</title>
<link>https://coderlegion.com/tag/sed</link>
<description>Powered by Question2Answer</description>
<item>
<title>I escaped the dot correctly and sed still rewrote a file marked DO NOT CHANGE</title>
<link>https://coderlegion.com/28023/i-escaped-the-dot-correctly-and-sed-still-rewrote-a-file-marked-do-not-change</link>
<description>&lt;p&gt;Four config files, one hostname to rename. I knew the dot in &lt;code&gt;api.internal&lt;/code&gt; is a regex wildcard, so I escaped it. &lt;code&gt;grep -rn 'api.internal'&lt;/code&gt; unescaped matched a fourth file containing &lt;code&gt;apiXinternal&lt;/code&gt; — a typo somebody deliberately kept. Escaped, &lt;code&gt;api\.internal&lt;/code&gt; matched three. Good.&lt;/p&gt;
&lt;p&gt;Then I ran the rename, and two of those three should never have changed: a line ending in &lt;code&gt;# DO NOT CHANGE&lt;/code&gt;, and a commented-out sample. My &lt;code&gt;-not -path &quot;*/samples/*&quot;&lt;/code&gt; exclusion did nothing, because the file was called &lt;code&gt;sample.conf&lt;/code&gt; and was not inside a &lt;code&gt;samples/&lt;/code&gt; directory.&lt;/p&gt;
&lt;p&gt;That is the real lesson, and escaping was never the whole answer. The dot is the trap everyone warns about; the trap that actually got me was assuming my exclusion pattern matched what I pictured. The fix is an order, not a flag — make &lt;code&gt;grep -l&lt;/code&gt; print the file list while everything is still read-only, and read it:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;find /etc/myapp -type f -name &quot;*.conf&quot; -exec grep -l &quot;api\.internal&quot; {} +
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If that list surprises you, the surprise &lt;em&gt;is&lt;/em&gt; the bug, and you found it before anything was written. Only then pipe it to &lt;code&gt;sed -i.bak&lt;/code&gt;, so every file keeps a rollback copy — and diff one against its &lt;code&gt;.bak&lt;/code&gt; before trusting the run. &lt;code&gt;sed -i&lt;/code&gt; exits 0 whether it changed four files or none.&lt;/p&gt;
&lt;p&gt;The awk summarizing stage and the incident-triage pipeline are in the &lt;a rel=&quot;nofollow&quot; href=&quot;https://bashsnippets.xyz/guides/bash-text-processing&quot;&gt;find, grep, sed and awk ordering guide&lt;/a&gt;.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/28023/i-escaped-the-dot-correctly-and-sed-still-rewrote-a-file-marked-do-not-change</guid>
<pubDate>Tue, 13 Oct 2026 13:00:00 +0000</pubDate>
</item>
</channel>
</rss>