<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vita di un sys-admin &#187; sed</title>
	<atom:link href="http://blog.angelofailla.com/tag/sed/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.angelofailla.com</link>
	<description>Storie, esperienze e pensieri da Dublino.</description>
	<lastBuildDate>Sun, 14 Aug 2011 22:11:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Io ti odio!</title>
		<link>http://blog.angelofailla.com/2009/02/14/io-ti-odio/</link>
		<comments>http://blog.angelofailla.com/2009/02/14/io-ti-odio/#comments</comments>
		<pubDate>Sat, 14 Feb 2009 11:19:39 +0000</pubDate>
		<dc:creator>pallotron</dc:creator>
				<category><![CDATA[Informatica]]></category>
		<category><![CDATA[Irlanda]]></category>
		<category><![CDATA[Lamentazioni]]></category>
		<category><![CDATA[Lavoro]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[odio]]></category>
		<category><![CDATA[oneliner]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[sed]]></category>

		<guid isPermaLink="false">http://blog.angelofailla.com/?p=1318</guid>
		<description><![CDATA[Caro collega, stavolta lo scrivo qui: ieri ti ho odiato, per l&#8217;ennesima volta! Quando il nostro collega DBA indiano e&#8217; venuto da me chiedendomi: «Angelo, come faccio ad inserire una stringa &#8220;NAME&#8221; su un file &#8220;tmp.log&#8221; da 1 GB tra la quarta e la quinta colonna con VI/VIM?» Tu hai sentito&#8230; ti sei voluto alzare&#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>Caro collega,</p>
<p>stavolta lo scrivo qui: ieri ti ho <strong>odiato</strong>, per l&#8217;ennesima volta!</p>
<p>Quando il nostro collega DBA indiano e&#8217; venuto da me chiedendomi:</p>
<blockquote><p>«Angelo, come faccio ad inserire una stringa &#8220;NAME&#8221; su un file &#8220;tmp.log&#8221; da 1 GB tra la quarta e la quinta colonna con VI/VIM?»</p></blockquote>
<p><strong>Tu hai sentito&#8230; ti sei voluto alzare&#8230; con quell&#8217;aria da saccente&#8230; *dovevi* intrometterti&#8230; il tuo istinto da &#8220;nerdone-primo-della-classe-so-tutto-io&#8221; ti ha fatto venire alla mia scrivania mentre io scrivevo il one-liner perl necessario alla magia, consigliandomi di poterlo fare cosi&#8217; e coli&#8217;&#8230; con sed piuttosto che con awk, e blabla&#8230;</strong></p>
<p style="text-align: center;"><strong><a href="http://blog.angelofailla.com/wp-content/uploads/2009/02/nerd.jpg"><img class="size-full wp-image-1320 aligncenter" title="nerd" src="http://blog.angelofailla.com/wp-content/uploads/2009/02/nerd.jpg" alt="nerd" width="300" height="370" /></a><br />
</strong></p>
<p>Non e&#8217; stato sufficiente che ti dicessi di farti i cazzi tuoi&#8230; dovevi gareggiare&#8230; dovevi farti sputtanare&#8230; e dopo 2 minuti hai avuto anche la sfacciataggine di mandare una email al collega col subject &#8220;sed version&#8221;, scrivendo questa zozzeria:</p>
<pre>$ cat tmp.log | sed 's/^\(\W*\w\+\W\+\w\+\W\+\W*\w\+\)/\1 fff/g'</pre>
<p>Ma ti ho punito con la eleganza del Perl:</p>
<pre>$ perl -lpne 's/^((\w+\W+){3})/$1NAME /;' tmp.log</pre>
<p><strong>Sei old! OLD! Mettitelo in testa. Guarda quella linea, e&#8217; ILLEGGIBILE. Con tutte quelle sequenze di escape!<br />
</strong></p>
<p><strong>Peccato che il DBA abbia scelto il tuo sed. In questo mondo non c&#8217;e&#8217; giustizia.<br />
</strong></p>
<img src="http://blog.angelofailla.com/?ak_action=api_record_view&id=1318&type=feed" alt="" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.angelofailla.com%2F2009%2F02%2F14%2Fio-ti-odio%2F&amp;title=Io%20ti%20odio%21" id="wpa2a_2"><img src="http://blog.angelofailla.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.angelofailla.com/2009/02/14/io-ti-odio/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Highlight text on the fly thanks to terminfo and sed.</title>
		<link>http://blog.angelofailla.com/2011/06/27/highlight-text-on-the-fly-thanks-to-terminfo-and-sed/</link>
		<comments>http://blog.angelofailla.com/2011/06/27/highlight-text-on-the-fly-thanks-to-terminfo-and-sed/#comments</comments>
		<pubDate>Mon, 27 Jun 2011 18:36:02 +0000</pubDate>
		<dc:creator>pallotron</dc:creator>
				<category><![CDATA[Informatica]]></category>
		<category><![CDATA[Lavoro]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[highlight]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[terminfo]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://blog.angelofailla.com/?p=2337</guid>
		<description><![CDATA[A colleague today was looking for a way to pipe something to a command that highlights particular strings of text, keeping intact the stdin, similar to what you can see on some modern distros, ie Gentoo. Grep is not the way as it only prints the lines which contain the pattern that we are looking [...]]]></description>
			<content:encoded><![CDATA[<p>A colleague today was looking for a way to pipe something to a command that highlights particular strings of text, keeping intact the stdin, similar to what you can see on some modern distros, ie Gentoo.</p>
<p>Grep is not the way as it only prints the lines which contain the pattern that we are looking for.</p>
<p>While there are a bunch of tools that can do that, like supercat, etc. I felt no need to install additional packages for something you can do with few lines of bash and knowing terminal capabilities.</p>
<p>Therefore I wrote this small script, put it in the PATH env variable. The script uses sed and makes use of the terminfo database and of the terminal capabilities to color the text, here it is in case you find it useful:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #007800;">red</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>tput bold;tput setaf <span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">normal</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>tput sgr0<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> line; <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$line</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/\($1\)/<span style="color: #007800;">$red</span>\1<span style="color: #007800;">$normal</span>/&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

<p>If you don&#8217;t like red just read `man tput` and read <a href="http://wiki.bash-hackers.org/scripting/terminalcodes">this link</a> about terminal codes.</p>
<p>Example of usage:</p>
<p><a href="http://blog.angelofailla.com/wp-content/uploads/2011/06/highlight.jpg"><img src="http://blog.angelofailla.com/wp-content/uploads/2011/06/highlight.jpg" alt="" title="highlight" width="607" height="284" class="aligncenter size-full wp-image-2343" /></a></p>
<p>It also accept regexps (in sed syntax, not perl syntax), for example:</p>
<p><code><br />
$ sudo tail -f /var/log/system.log | highlight [Ss]potify<br />
</code></p>
<img src="http://blog.angelofailla.com/?ak_action=api_record_view&id=2337&type=feed" alt="" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.angelofailla.com%2F2011%2F06%2F27%2Fhighlight-text-on-the-fly-thanks-to-terminfo-and-sed%2F&amp;title=Highlight%20text%20on%20the%20fly%20thanks%20to%20terminfo%20and%20sed." id="wpa2a_4"><img src="http://blog.angelofailla.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.angelofailla.com/2011/06/27/highlight-text-on-the-fly-thanks-to-terminfo-and-sed/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

