Bash: Syntax highlighting for tail (with awk)
<p>I'm using tail and awk to do syntax highlighting on my log file.</p>

<p>This is my highlighter:
<strong>tailError.sh</strong></p>

<pre><code> tail -f error.log | awk '
 /INFO/  {print "\033[1;37m" $0 "\033[39m"} 
 /ERROR/ {print "\033[31m"   $0 "\033[39m"}
 /WARN/  {print "\033[33m"   $0 "\033[39m"}
 /DEBUG/ {print "\033[0;37m" $0 "\033[39m"}
 /at com.adobe.training/ {print "\033[31m" $0 "\033[39m"}
 '
</code></pre>

<p>This is very close to
<a href="https://unix.stackexchange.com/questions/8414/how-to-have-tail-f-show-colored-output">https://unix.stackexchange.com/questions/8414/how-to-have-tail-f-show-colored-output</a></p>

<p>Let's say, this is my log file (<strong>error.log</strong>):</p>

<pre><code>*INFO* Really?
*WARN* Take care
*ERROR* Doh!
Exception in thread "main" NullPointerException
    at com.adobe.training.methodWithNPE (MyClass.java:123)
    at somewhere.else (Servlet.java:234) --- This line should be printed, too --
--- This line and the next one are missing. ---
 --- How do I output these lines? ---
</code></pre>

<p>And the output looks like that:
<a href="https://i.stack.imgur.com/zY6oG.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zY6oG.gif" alt="enter image description here"></a></p>

<p>As you can see, these lines from my log file are missing:</p>

<pre><code>at somewhere.else (Servlet.java:234) --- This line should be printed, too --
--- This line and the next one are missing. ---
--- How do I output these lines? ---
</code></pre>

<p>How do I output these lines?</p>

<p>I guess, there should be sth. like an <em>else</em> in my awk statement:</p>

<pre><code>awk '/INFO/ { print $0 } /ERROR/ { print $0 } /EVERYTHING_ELSE/ { print $0 }'
</code></pre>

<p>Thanks
Bernhard</p>

<p>UPDATE:
Here is the updated <strong>tailError.sh:</strong>, which works as expected.
Thank you, jas.</p>

<pre><code>tail -f error.log | awk '
    /INFO/  {print "\033[1;37m" $0 "\033[39m"; next} 
    /ERROR/ {print "\033[31m"   $0 "\033[39m"; next}
    /WARN/  {print "\033[33m"   $0 "\033[39m"; next}
    /DEBUG/ {print "\033[0;37m" $0 "\033[39m"; next}
    /at com.adobe.training/ {print "\033[31m" $0 "\033[39m"; next}
    {print $0}
'
</code></pre>