<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged grep</title>
<link>https://coderlegion.com/tag/grep</link>
<description>Powered by Question2Answer</description>
<item>
<title>Why grep &quot;error|failed&quot; finds nothing in a log full of failures</title>
<link>https://coderlegion.com/28026/why-grep-error-failed-finds-nothing-in-a-log-full-of-failures</link>
<description>&lt;p&gt;If grep returns empty on a file you know contains matches, suspect the pattern before the file. Default grep uses Basic Regular Expressions (BRE), where &lt;code&gt;|&lt;/code&gt;, &lt;code&gt;+&lt;/code&gt;, &lt;code&gt;?&lt;/code&gt;, and &lt;code&gt;()&lt;/code&gt; are literal characters unless backslash-escaped. So &lt;code&gt;grep &quot;error|failed&quot; app.log&lt;/code&gt; searches for the literal twelve-character string &lt;code&gt;error|failed&lt;/code&gt; — pipe included — which no logger ever writes. Alternation needs Extended Regular Expressions via &lt;code&gt;-E&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;grep &quot;error|failed&quot; app.log     # BRE: literal string, matches nothing
grep -E &quot;error|failed&quot; app.log  # ERE: matches either word
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The dangerous part is the exit behavior. An impossible pattern is not a syntax error, so grep exits 1 — the same code as &quot;no matches in a clean file&quot; — and prints nothing. A wrong question and a healthy log look identical, which is how this bug hides inside monitoring checks and cron pipelines for days.&lt;/p&gt;
&lt;p&gt;Two related traps: &lt;code&gt;-P&lt;/code&gt; (Perl regex, &lt;code&gt;\d&lt;/code&gt;, lookaheads) is GNU-only and fails on macOS/BSD grep, and bare grep aimed at a directory refuses with &quot;Is a directory&quot; unless &lt;code&gt;-r&lt;/code&gt; is set.&lt;/p&gt;
&lt;p&gt;When I'm unsure what a pattern will match, I assemble the command in this &lt;a rel=&quot;nofollow&quot; href=&quot;https://bashsnippets.xyz/tools/grep-pattern-builder&quot;&gt;grep command builder with a live match tester&lt;/a&gt; — paste a sample line you know should match, and a zero count tells you the pattern is the bug before the empty result gets believed.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/28026/why-grep-error-failed-finds-nothing-in-a-log-full-of-failures</guid>
<pubDate>Thu, 22 Oct 2026 13:00:00 +0000</pubDate>
</item>
</channel>
</rss>