<?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>Adventures in Autodidacticism.</title>
	<atom:link href="http://codetwit.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://codetwit.com</link>
	<description></description>
	<lastBuildDate>Fri, 04 May 2012 14:01:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Puppet Training</title>
		<link>http://codetwit.com/sysadmin/2012/05/puppet-training/</link>
		<comments>http://codetwit.com/sysadmin/2012/05/puppet-training/#comments</comments>
		<pubDate>Fri, 04 May 2012 03:54:35 +0000</pubDate>
		<dc:creator>snyce</dc:creator>
				<category><![CDATA[DevOps]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[puppet]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=591</guid>
		<description><![CDATA[For the last three days I have been in Puppet training (April 28th &#8211; May 1st), which rocked, completely. The trainer Hunter Haugen was awesome, not only is he extremely knowledgeable (just don&#8217;t throw down the W word) but thoughtful, honest, and took the time to listen to our pain points and give some good [...]]]></description>
			<content:encoded><![CDATA[<p>For the last three days I have been in Puppet training (April 28th &#8211; May 1st), which rocked, completely. The trainer <a href="https://github.com/hunner">Hunter Haugen</a> was awesome, not only is he extremely knowledgeable (just don&#8217;t throw down the W word) but thoughtful, honest, and took the time to listen to our pain points and give some good advice (you can read his <a href="http://hunnur.com/blog/">blog here</a> for fantastic tips on vim). I am not going to bore you with the details of the training, other than to say if you&#8217;re considering using Puppet in your environment, shell out for the training, it is definitely worth it.</p>
]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/sysadmin/2012/05/puppet-training/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interview Questions &#8230; Renaming files in a given directory en masse.</title>
		<link>http://codetwit.com/interview-questions/2012/04/iq_renaming_files_en_masse/</link>
		<comments>http://codetwit.com/interview-questions/2012/04/iq_renaming_files_en_masse/#comments</comments>
		<pubDate>Sun, 29 Apr 2012 16:25:07 +0000</pubDate>
		<dc:creator>snyce</dc:creator>
				<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[basename]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[mv]]></category>
		<category><![CDATA[rename]]></category>
		<category><![CDATA[sed]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=556</guid>
		<description><![CDATA[Q: Rename all .html files in dir to .htm A: Obviously there are quite a few ways to do this, here are just a couple. So for testing purposes we'll create a directory in /tmp, say test and cd there: prompt:&#62; mkdir /tmp/test prompt:&#62; cd !$ Now we'll create a few temporary html files to [...]]]></description>
			<content:encoded><![CDATA[<pre>
Q: Rename all .html files in dir to .htm

A: Obviously there are quite a few ways to do this, here are just a couple.

So for testing purposes we'll create a directory in /tmp, say test and cd there:
</pre>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1">prompt:<span class="sy0">&gt;</span> <span class="kw2">mkdir</span> <span class="sy0">/</span>tmp<span class="sy0">/</span><span class="kw3">test</span>
prompt:<span class="sy0">&gt;</span> <span class="kw3">cd</span> <span class="sy0">!</span>$</pre></div></div></div></div></div></div></div>


<pre>
Now we'll create a few temporary html files to rename.
</pre>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1">prompt:<span class="sy0">&gt;</span> <span class="kw1">for</span> i <span class="kw1">in</span> <span class="br0">&#123;</span><span class="nu0">1</span>..<span class="nu0">10</span><span class="br0">&#125;</span>; <span class="kw1">do</span> <span class="kw2">touch</span> <span class="re1">$i</span>.html; <span class="kw1">done</span></pre></div></div></div></div></div></div></div>


<pre>
Now to rename them en masse:
First way (courtesy of Basketcase):
</pre>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1">prompt:<span class="sy0">&gt;</span> <span class="kw1">for</span> i <span class="kw1">in</span> $<span class="br0">&#40;</span><span class="kw2">ls</span> <span class="sy0">*</span>html<span class="br0">&#41;</span>; <span class="kw1">do</span> <span class="kw2">mv</span> <span class="re1">$i</span> $<span class="br0">&#40;</span><span class="kw3">echo</span> <span class="re1">$i</span> <span class="sy0">|</span> <span class="kw2">sed</span> <span class="st_h">'s/\(.*\)html/\1htm/'</span><span class="br0">&#41;</span>; <span class="kw1">done</span></pre></div></div></div></div></div></div></div>


<pre>
Second way (courtesy of myself):
</pre>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1">prompt:<span class="sy0">&gt;</span> <span class="kw1">for</span> i <span class="kw1">in</span> $<span class="br0">&#40;</span><span class="kw2">ls</span> <span class="sy0">*</span>html<span class="br0">&#41;</span>; <span class="kw1">do</span> <span class="kw2">mv</span> <span class="re1">$i</span> $<span class="br0">&#40;</span><span class="kw2">basename</span> <span class="re1">$i</span> .html<span class="br0">&#41;</span>.htm; <span class="kw1">done</span></pre></div></div></div></div></div></div></div>


<pre>
First way breakdown:
	1. loop through all the specified files, *html in our case.
	2. here is where the magic with sed happens, echo the filename $i, then use sed to greedy match our pattern and substitute it with the new pattern. We use the first part of the matching pattern with "\1" (which will expand to 1. 2. 3., etc) and then replace the last part of the pattern. As an example of this try in the working directory "for i in $(ls); do echo $i | sed 's/\(.*\)htm/\1/'; done" without doing the replacement, it should print all the files and the ones that match should be printed as "filename.", so in our dir it should look something like 1. 2. 3. 4. 5., etc.

Second way breakdown:
	1. loop through all the specified files, *html in our case.
	2. use basename utility to strip off the first pattern (.html) as we move the file to .htm. 

So I created 10k files 1-10000.html and timed the following two commands, this is by no means scientific, I was just curious what the timing was on each of them with more than 10 files.

On 10k files with first method:
</pre>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1">prompt:<span class="sy0">&gt;</span> <span class="kw1">time</span> <span class="kw1">for</span> i <span class="kw1">in</span> $<span class="br0">&#40;</span><span class="kw2">ls</span><span class="br0">&#41;</span>; <span class="kw1">do</span> <span class="kw2">mv</span> <span class="re1">$i</span> $<span class="br0">&#40;</span><span class="kw3">echo</span> <span class="re1">$i</span> <span class="sy0">|</span> <span class="kw2">sed</span> <span class="st_h">'s/\(.*\).html/\1htm/'</span><span class="br0">&#41;</span>; <span class="kw1">done</span>
&nbsp;
real	1m36.604s
user	0m15.842s
sys	0m58.361s</pre></div></div></div></div></div></div></div>


<pre>
On 10k files with second method:
</pre>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1">prompt:<span class="sy0">&gt;</span> <span class="kw1">time</span> <span class="kw1">for</span> i <span class="kw1">in</span> $<span class="br0">&#40;</span><span class="kw2">ls</span><span class="br0">&#41;</span>; <span class="kw1">do</span> <span class="kw2">mv</span> <span class="re1">$i</span> $<span class="br0">&#40;</span><span class="kw2">basename</span> <span class="re1">$i</span> .htm<span class="br0">&#41;</span>.html; <span class="kw1">done</span>
real	1m4.737s
user	0m9.260s
sys	0m38.631s</pre></div></div></div></div></div></div></div>


<pre>
First way, with backtick `` interpolation:
</pre>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1">prompt:<span class="sy0">&gt;</span> <span class="kw1">time</span> <span class="kw1">for</span> i <span class="kw1">in</span> <span class="sy0">`</span><span class="kw2">ls</span> <span class="sy0">*</span>html<span class="sy0">`</span>; <span class="kw1">do</span> <span class="kw2">mv</span> <span class="re1">$i</span> <span class="sy0">`</span><span class="kw3">echo</span> <span class="re1">$i</span> <span class="sy0">|</span> <span class="kw2">sed</span> <span class="st_h">'s/\(.*\)html/\1htm/'</span><span class="sy0">`</span>; <span class="kw1">done</span>
&nbsp;
real	1m18.076s
user	0m15.478s
sys	0m56.438s</pre></div></div></div></div></div></div></div>


<pre>
<b><i>Addendum:</i></b>
Basketcase also pointed out that using perl rename is much faster, though since I am on an OSX box, it is not native and hence why I personally chose not to go that route.
</pre>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1">linux prompt:<span class="sy0">&gt;</span> <span class="kw1">time</span> rename  <span class="st_h">'s/\.html/\.htm/'</span> <span class="sy0">*</span>.html
&nbsp;
real    0m0.270s
user    0m0.204s
sys    0m0.064s</pre></div></div></div></div></div></div></div>


]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/interview-questions/2012/04/iq_renaming_files_en_masse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning Haskell for a Greater Good!</title>
		<link>http://codetwit.com/coding/2012/04/learning-haskell-for-a-greater-good/</link>
		<comments>http://codetwit.com/coding/2012/04/learning-haskell-for-a-greater-good/#comments</comments>
		<pubDate>Thu, 12 Apr 2012 15:01:00 +0000</pubDate>
		<dc:creator>snyce</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=537</guid>
		<description><![CDATA[tl;dr &#8211; Learning Haskell and functional programming, yay! So I have finally decided after years of using imperative style languages that I am going to Learn me some Haskell for a greater good, as I have been curious about the functional side of programming. Now it has taken me quite some time to get here, [...]]]></description>
			<content:encoded><![CDATA[<p>tl;dr &#8211; Learning Haskell and functional programming, yay!</p>
<p>So I have finally decided after years of using imperative style languages that I am going to <a href="http://learnyouahaskell.com/">Learn me some Haskell for a greater good</a>, as I have been curious about the functional side of programming. Now it has taken me quite some time to get here, I have been toying with the idea of functional programming for quite a while, just haven&#8217;t gotten around to it as the imperative languages seem to be just fine for what I do for a living, Systems Administration/Engineering. I have been toying with either learning Haskell or Erlang, and have decided on Haskell. Why?, well I don&#8217;t really know just kind of happened that I chose Haskell. </p>
<p>About a day after I started reading <a href="http://learnyouahaskell.com">Learn you a Haskell for a Great Good!</a> I noticed this <a href="http://fpcomplete.com/the-downfall-of-imperative-programming/">article &#8211; (The Downfall of Imperative Programming)</a> fly across my twitter stream from <a href="https://twitter.com/#!/LordCope">@LordCope</a>. Now, it is a well written article and surprisingly the comments are for the most part well thought out (I really abhor reading commentary on the internets), and I have to agree with what Bartosz says here in response to a comment about functional programming being the downfall of the imperative languages, &#8220;Of course it’s an exaggeration :-) . Just like object oriented programming didn’t eliminate C, Haskell will not eliminate Java. It will just dislodge it into its well deserved niche.&#8221; I personally, and honestly think that to be the best that one can be it is sometimes necessary to open one&#8217;s mind and try new things, and for me right now that is Haskell and functional programming, and so far I am really enjoying myself. </p>
<p>After I finish with <a href="http://learnyouahaskell.com/">Learn you a Haskell for Great Good!</a> I am going to move on to <a href="http://book.realworldhaskell.org/">Real World Haskell</a> which is also freely available online, and while I am not associated with any of the authors in any way, shape or form, if you like the books I strongly encourage you to purchase them as they require a lot of effort to write.</p>
]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/coding/2012/04/learning-haskell-for-a-greater-good/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Aliases &#8211; Linux</title>
		<link>http://codetwit.com/sysadmin/2012/03/aliases-linux/</link>
		<comments>http://codetwit.com/sysadmin/2012/03/aliases-linux/#comments</comments>
		<pubDate>Fri, 30 Mar 2012 01:24:42 +0000</pubDate>
		<dc:creator>snyce</dc:creator>
				<category><![CDATA[System Administration]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=533</guid>
		<description><![CDATA[So sitting here on the train I got to thinking about some of the standard aliases that I use, or add to a system upon first installation and use. This does not stave off the infamous &#8220;rm -rf &#8211; pebkac error&#8221; but to keep myself from general stupidity I tend alias rm, cp and mv [...]]]></description>
			<content:encoded><![CDATA[<p>So sitting here on the train I got to thinking about some of the standard aliases that I use, or add to a system upon first installation and use. </p>
<p>This does not stave off the infamous &#8220;rm -rf &#8211; pebkac error&#8221; but to keep myself from general stupidity I tend alias rm, cp and mv first and foremost (that way for the most part if I make a bad decision at least I was prompted to):</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1"><span class="kw3">alias</span> <span class="re2">rm</span>=<span class="st_h">'rm -i'</span>
<span class="kw3">alias</span> <span class="re2">cp</span>=<span class="st_h">'cp -i'</span>
<span class="kw3">alias</span> <span class="re2">mv</span>=<span class="st_h">'mv -i'</span></pre></div></div></div></div></div></div></div>


<p>Also, back in the day, when I started messing with Linux, I loved the terminal colors, now not so much. So I alias away the colors, make them appear in columns and with characters to denote the type of file (&#8216;/&#8217; for directory, &#8216;*&#8217; for executable, etc.).</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1"><span class="kw3">alias</span> <span class="re2">ls</span>=<span class="st_h">'ls -CF'</span></pre></div></div></div></div></div></div></div>


<p>Because &#8220;maths are teh hard&#8221; I tend to alias df so that it appears in human readable format. Sometimes I&#8217;ll alias free, but not always &#8211; sometimes I like to live dangerously. Conversely since I tend to work mainly on OSX and free isn&#8217;t a built in (yes I know it can be added with ports), I tend to just forget about it.</p>
<p>At the end I will then setup personal aliases that are meaningful to me, but may not have any meaning to someone not living inside my head. For instance if there are a few hosts that I know that I will be sshing to quite frequently, like say jump hosts, I will alias them down to singular commands, usually the hosts name to make getting there quicker and easier. </p>
]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/sysadmin/2012/03/aliases-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Printing column headers from commands</title>
		<link>http://codetwit.com/sysadmin/2012/03/printing-column-headers-from-commands/</link>
		<comments>http://codetwit.com/sysadmin/2012/03/printing-column-headers-from-commands/#comments</comments>
		<pubDate>Thu, 22 Mar 2012 15:19:22 +0000</pubDate>
		<dc:creator>snyce</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[df]]></category>
		<category><![CDATA[netstat]]></category>
		<category><![CDATA[sed]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=512</guid>
		<description><![CDATA[As with most things in *nix world there are more than one way of doing things. Here is a nifty trick I picked up from a former coworker. Sometimes when I needed to do disk reporting it was handy to have the column header (remember this is my use case) for those who don&#8217;t necessarily [...]]]></description>
			<content:encoded><![CDATA[<p>As with most things in *nix world there are more than one way of doing things. Here is a nifty trick I picked up from a former coworker. Sometimes when I needed to do disk reporting it was handy to have the column header (remember this is my use case) for those who don&#8217;t necessarily know what the columns mean when doing a df or similar and grepping for a particular volume / disk (read upper management). I am fairly certain that there are even more ways of accomplishing this, but here are two that I&#8217;ve used. Also be aware, that you need to know what you&#8217;re looking for, or the pattern you need to match.</p>
<p>Note: this was done from my MBP, so in Linux ymmv*.</p>
<p>sed:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="sed"><pre class="de1">Before:
df -h | grep disk
&nbsp;
/dev/disk0s2    465Gi  123Gi  342Gi    27%    /
/dev/disk1s2    110Mi   94Mi   16Mi    86%    /Volumes/VirtualBox
/dev/disk2s0s2   25Mi   22Mi  2.7Mi    90%    /Volumes/VZAccess Manager
&nbsp;
After:
df -h | sed -n '/^Filesystem/p;/disk/p'
&nbsp;
Filesystem       Size   Used  Avail Capacity  Mounted on
/dev/disk0s2    465Gi  123Gi  342Gi    27%    /
/dev/disk1s2    110Mi   94Mi   16Mi    86%    /Volumes/VirtualBox
/dev/disk2s0s2   25Mi   22Mi  2.7Mi    90%    /Volumes/VZAccess Manager</pre></div></div></div></div></div></div></div>


<p>awk:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="awk"><pre class="de1">Before<span class="sy5">:</span>
df <span class="sy3">-</span>h | grep disk
&nbsp;
<span class="sy3">/</span>dev<span class="sy3">/</span>disk0s2    465Gi  123Gi  342Gi    <span class="nu0">27</span><span class="sy3">%</span>    <span class="sy3">/</span>
<span class="sy3">/</span>dev<span class="sy3">/</span>disk1s2    110Mi   94Mi   16Mi    <span class="nu0">86</span><span class="sy3">%</span>    <span class="sy3">/</span>Volumes<span class="sy3">/</span>VirtualBox
<span class="sy3">/</span>dev<span class="sy3">/</span>disk2s0s2   25Mi   22Mi  2.7Mi    <span class="nu0">90</span><span class="sy3">%</span>    <span class="sy3">/</span>Volumes<span class="sy3">/</span>VZAccess Manager
&nbsp;
After<span class="sy5">:</span>
df <span class="sy3">-</span>h | awk '<span class="sy3">/^</span>Filesystem <span class="br0">&#123;</span><span class="kw5">print</span>;<span class="br0">&#125;</span>; <span class="sy3">/</span>disk<span class="sy3">/</span> <span class="br0">&#123;</span><span class="kw5">print</span>;<span class="br0">&#125;</span>; <span class="br0">&#123;</span>next;<span class="br0">&#125;</span>;'
&nbsp;
Filesystem       Size   Used  Avail Capacity  Mounted on
<span class="sy3">/</span>dev<span class="sy3">/</span>disk0s2    465Gi  123Gi  342Gi    <span class="nu0">27</span><span class="sy3">%</span>    <span class="sy3">/</span>
<span class="sy3">/</span>dev<span class="sy3">/</span>disk1s2    110Mi   94Mi   16Mi    <span class="nu0">86</span><span class="sy3">%</span>    <span class="sy3">/</span>Volumes<span class="sy3">/</span>VirtualBox
<span class="sy3">/</span>dev<span class="sy3">/</span>disk2s0s2   25Mi   22Mi  2.7Mi    <span class="nu0">90</span><span class="sy3">%</span>    <span class="sy3">/</span>Volumes<span class="sy3">/</span>VZAccess Manager</pre></div></div></div></div></div></div></div>


<p>sed breakdown:<br />
With the sed line we are matching any line that begins with Filesystem &#8220;/^Filesystem&#8221; and printing it &#8220;/p&#8221;, then matching any line that has disk &#8220;/disk&#8221; and printing it &#8220;/p&#8221;. The &#8220;-n&#8221; option to sed tells it to only print what we are looking for &#8211; from the sed manpage on OSX &#8211; <i><b>&#8220;-n By default, each line of input is echoed to the standard output after all of the commands have been applied to it.  The -n option suppresses this behavior.&#8221;</b></i> If you were to remove the &#8220;-n&#8221; switch it would look something like this:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="sed"><pre class="de1">&nbsp;
df -h | sed '/^Filesystem/p;/disk/p'
&nbsp;
Filesystem       Size   Used  Avail Capacity  Mounted on
Filesystem       Size   Used  Avail Capacity  Mounted on
/dev/disk0s2    465Gi  123Gi  342Gi    27%    /
/dev/disk0s2    465Gi  123Gi  342Gi    27%    /
devfs           199Ki  199Ki    0Bi   100%    /dev
map -hosts        0Bi    0Bi    0Bi   100%    /net
map auto_home     0Bi    0Bi    0Bi   100%    /home
/dev/disk1s2    110Mi   94Mi   16Mi    86%    /Volumes/VirtualBox
/dev/disk1s2    110Mi   94Mi   16Mi    86%    /Volumes/VirtualBox
/dev/disk2s0s2   25Mi   22Mi  2.7Mi    90%    /Volumes/VZAccess Manager
/dev/disk2s0s2   25Mi   22Mi  2.7Mi    90%    /Volumes/VZAccess Manager</pre></div></div></div></div></div></div></div>


<p>printing the matches multiple times due to matching on the &#8220;/^Filesystem&#8221; and matching on the &#8220;/disk&#8221;.</p>
<p>awk breakdown:<br />
With the awk one, we are matching the line that begins with &#8220;/^Filesystem&#8221; and printing it, then matching the line with &#8220;/disk/&#8221; and printing, then followed by a statement &#8220;{next;}&#8221; to keep processing and skip unless the pattern matches.</p>
<p>Also while writing the post, thought of another one that it might be useful, though it really depends on what you&#8217;re running on your system. Thought of a little netstat example though I will go with the caveat here that netstat can easily make this a moot point, take this with a grain of salt.</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="sed"><pre class="de1">Before:
&nbsp;
netstat -anl | grep -i listen
&nbsp;
tcp46      0      0  *.9292                 *.*                    LISTEN     
tcp46      0      0  *.9302                 *.*                    LISTEN     
tcp46      0      0  *.9301                 *.*                    LISTEN     
tcp46      0      0  *.9200                 *.*                    LISTEN     
tcp46      0      0  *.9300                 *.*                    LISTEN     
tcp46      0      0  *.62056                *.*                    LISTEN     
tcp4       0      0  *.62056                *.*                    LISTEN     
tcp4       0      0  127.0.0.1.51093        *.*                    LISTEN     
tcp4       0      0  127.0.0.1.26164        *.*                    LISTEN     
tcp4       0      0  *.17500                *.*                    LISTEN     
tcp4       0      0  127.0.0.1.631          *.*                    LISTEN     
tcp6       0      0  ::1.631                                       *.*                                           LISTEN     
ffffff80147a27d0 stream      0      0 ffffff8017e13f00                0                0                0 /tmp/launch-H5oHbg/Listeners
&nbsp;
After:
&nbsp;
netstat -anl | sed -n '/^Proto/p;/LISTEN/p'
&nbsp;
Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)    
tcp46      0      0  *.9292                 *.*                    LISTEN     
tcp46      0      0  *.9302                 *.*                    LISTEN     
tcp46      0      0  *.9301                 *.*                    LISTEN     
tcp46      0      0  *.9200                 *.*                    LISTEN     
tcp46      0      0  *.9300                 *.*                    LISTEN     
tcp46      0      0  *.62056                *.*                    LISTEN     
tcp4       0      0  *.62056                *.*                    LISTEN     
tcp4       0      0  127.0.0.1.51093        *.*                    LISTEN     
tcp4       0      0  127.0.0.1.26164        *.*                    LISTEN     
tcp4       0      0  *.17500                *.*                    LISTEN     
tcp4       0      0  127.0.0.1.631          *.*                    LISTEN     
tcp6       0      0  ::1.631                                       *.*                                           LISTEN</pre></div></div></div></div></div></div></div>


<p>Again, this makes the presumption that you know what you&#8217;re looking for, and if you tried to do that with ESTABLISHED in netstat it may be moot unless you narrowed down to less than a screen. Also I&#8217;ll leave the awk version and looking for specific ports / port ranges as an exercise for the reader. Also astute readers will notice that we lost the last output from the first netstat command due to not grepping indiscriminately.</p>
<p>I hope this information comes in handy, share and enjoy!</p>
<p>*For those that may not know, ymmv = Your Mileage May Vary.</p>
]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/sysadmin/2012/03/printing-column-headers-from-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making multiple directories (with parents)</title>
		<link>http://codetwit.com/sysadmin/2012/03/making-multiple-directories-with-parents/</link>
		<comments>http://codetwit.com/sysadmin/2012/03/making-multiple-directories-with-parents/#comments</comments>
		<pubDate>Thu, 22 Mar 2012 03:53:05 +0000</pubDate>
		<dc:creator>snyce</dc:creator>
				<category><![CDATA[System Administration]]></category>
		<category><![CDATA[mkdir]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=508</guid>
		<description><![CDATA[I know that this is general knowledge, but putting it down here so I remember where I put it. So to create multiple directories with the structure ~/projects/code/ I would use: localhost: mkdir -p ~/projects/code/&#123;c,perl,python,ruby,shell&#125; Got the reference for it here. *I always forget the which is correct &#8220;{&#8221; vs &#8220;[&#8220;.]]></description>
			<content:encoded><![CDATA[<p>I know that this is general knowledge, but putting it down here so I remember where I put it. So to create multiple directories with the structure ~/projects/code/<languages> I would use:</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1">localhost: <span class="kw2">mkdir</span> <span class="re5">-p</span> ~<span class="sy0">/</span>projects<span class="sy0">/</span>code<span class="sy0">/</span><span class="br0">&#123;</span>c,<span class="kw2">perl</span>,python,ruby,shell<span class="br0">&#125;</span></pre></div></div></div></div></div></div></div>


<p>Got the reference for it <a href="http://technosophos.com/content/mkdir-creating-multiple-subdirectories-one-command">here.</a> *I always forget the which is correct &#8220;{&#8221; vs &#8220;[&#8220;.</p>
]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/sysadmin/2012/03/making-multiple-directories-with-parents/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Okay, okay I suck&#8230;</title>
		<link>http://codetwit.com/thoughts/2012/02/okay-okay-i-suck/</link>
		<comments>http://codetwit.com/thoughts/2012/02/okay-okay-i-suck/#comments</comments>
		<pubDate>Fri, 24 Feb 2012 04:48:56 +0000</pubDate>
		<dc:creator>snyce</dc:creator>
				<category><![CDATA[Thoughts]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=503</guid>
		<description><![CDATA[Well hello there. I was planning on putting together some long drawn out post about starting to blog again, but figured what the hell, might as well just start doing it. So, though it has been a while, and a new job has been acquired (main reason behind the lack of postage in the preceding [...]]]></description>
			<content:encoded><![CDATA[<p>Well hello there. I was planning on putting together some long drawn out post about starting to blog again, but figured what the hell, might as well just start doing it. So, though it has been a while, and a new job has been acquired (main reason behind the lack of postage in the preceding months) that will all be covered in time. I also need to figure out a way to get basketcase to post again, maybe I&#8217;ll throw something at him when next I see him. So, I will be back shortly with more braindumpage, and hopefully some useful tidbits in there from time to time.</p>
]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/thoughts/2012/02/okay-okay-i-suck/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning Python Resources</title>
		<link>http://codetwit.com/coding/2011/09/learning-python-resources/</link>
		<comments>http://codetwit.com/coding/2011/09/learning-python-resources/#comments</comments>
		<pubDate>Sun, 04 Sep 2011 21:10:31 +0000</pubDate>
		<dc:creator>basketcase</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=489</guid>
		<description><![CDATA[I originally posted this on my blog http://www.barrymorrison.com/2011/09/04/learning-python-resources/ but thought it&#8217;d be a good fit over hear as well. These are simply links to Python resources I&#8217;ve collected recently in an effort to tech myself Python. Hopefully others can find it equally valuable. http://code.google.com/edu/languages/google-python-class/index.html http://i.imgur.com/YQafj.png http://code.google.com/appengine/docs/python/gettingstarted/ http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/ http://diveintopython.org/toc/index.html http://codingbat.com/ http://www.lightbird.net/py-by-example/ http://rgruet.free.fr/PQR26/PQR2.6.html http://www.udemy.com/learn-python-the-hard-way/ http://learnpythonthehardway.org/ http://www.swaroopch.com/notes/Python http://www.pythonchallenge.com/ [...]]]></description>
			<content:encoded><![CDATA[<p>I originally posted this on my blog <a title="http://www.barrymorrison.com/2011/09/04/learning-python-resources/" href="http://www.barrymorrison.com/2011/09/04/learning-python-resources/" target="_blank">http://www.barrymorrison.com/2011/09/04/learning-python-resources/</a> but thought it&#8217;d be a good fit over hear as well. These are simply links to Python resources I&#8217;ve collected recently in an effort to tech myself Python. Hopefully others can find it equally valuable.</p>
<p><a title="http://code.google.com/edu/languages/google-python-class/index.html" href="http://code.google.com/edu/languages/google-python-class/index.html" target="_blank">http://code.google.com/edu/languages/google-python-class/index.html</a></p>
<p><a title="http://i.imgur.com/YQafj.png" href="http://i.imgur.com/YQafj.png" target="_blank">http://i.imgur.com/YQafj.png</a></p>
<p><a title="http://code.google.com/appengine/docs/python/gettingstarted/" href="http://code.google.com/appengine/docs/python/gettingstarted/" target="_blank">http://code.google.com/appengine/docs/python/gettingstarted/</a></p>
<p><a title="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/" href="http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/" target="_blank">http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00-introduction-to-computer-science-and-programming-fall-2008/</a></p>
<p><a title="http://diveintopython.org/toc/index.html" href="http://diveintopython.org/toc/index.html" target="_blank">http://diveintopython.org/toc/index.html</a></p>
<p><a title="http://codingbat.com/" href="http://codingbat.com/" target="_blank">http://codingbat.com/</a></p>
<p><a title="http://www.lightbird.net/py-by-example/" href="http://www.lightbird.net/py-by-example/" target="_blank">http://www.lightbird.net/py-by-example/</a></p>
<p><a title="http://rgruet.free.fr/PQR26/PQR2.6.html" href="http://rgruet.free.fr/PQR26/PQR2.6.html" target="_blank">http://rgruet.free.fr/PQR26/PQR2.6.html</a></p>
<p><a title="http://www.udemy.com/learn-python-the-hard-way/" href="http://www.udemy.com/learn-python-the-hard-way/" target="_blank">http://www.udemy.com/learn-python-the-hard-way/</a></p>
<p><a title="http://learnpythonthehardway.org/" href="http://learnpythonthehardway.org/" target="_blank">http://learnpythonthehardway.org/</a></p>
<p><a title="http://www.swaroopch.com/notes/Python" href="http://www.swaroopch.com/notes/Python" target="_blank">http://www.swaroopch.com/notes/Python</a></p>
<p><a title="http://www.pythonchallenge.com/" href="http://www.pythonchallenge.com/" target="_blank">http://www.pythonchallenge.com/</a></p>
<p><a title="http://www.youtube.com/user/thenewboston#p/search/0/4Mf0h3HphEA" href="http://www.youtube.com/user/thenewboston#p/search/0/4Mf0h3HphEA" target="_blank">http://www.youtube.com/user/thenewboston#p/search/0/4Mf0h3HphEA</a></p>
]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/coding/2011/09/learning-python-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get Yesterday&#8217;s Date</title>
		<link>http://codetwit.com/coding/2011/08/get-yesterdays-date/</link>
		<comments>http://codetwit.com/coding/2011/08/get-yesterdays-date/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 00:37:53 +0000</pubDate>
		<dc:creator>basketcase</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[yesterday]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=326</guid>
		<description><![CDATA[I was working on a script that parsed log files. The file names were log.mmddyy (log.080811). This was a little bit of a learning experience for me (new to shell scripting). I was working on a Solaris 10 box, but I thought I&#8217;d do all my dev/testing on Ubuntu. Big mistake. Linux was running bash/gnu [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on a script that parsed log files.  The file names were log.mmddyy (log.080811).  This was a little bit of a learning experience for me (new to shell scripting).  I was working on a Solaris 10 box, but I thought I&#8217;d do all my dev/testing on Ubuntu.  Big mistake.  Linux was running bash/gnu tools.  Solaris was not.  After I figured out how to do it on Ubuntu, I had to figure out how to do it on Solaris (thanks Scott!), then I did it in Powershell (had done something similar already for another script) and since I&#8217;m teaching myself Python, I wanted to do it in Python. </p>
<p>Are they the &#8220;right&#8221; way to do them?  They work!  Probably not a &#8220;right&#8221; way to do them, as there is always more than one way to do something</p>
<h3>Shell</h3>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1"><span class="co0">#!/bin/bash</span>
&nbsp;
<span class="re2">os</span>=<span class="sy0">`</span><span class="kw2">uname</span><span class="sy0">`</span>
&nbsp;
<span class="kw1">if</span> <span class="br0">&#91;</span> <span class="re1">$os</span> == <span class="st_h">'Linux'</span> <span class="br0">&#93;</span>;
    <span class="kw1">then</span>
    <span class="re2">yesterday</span>=<span class="sy0">&amp;</span>quot;$<span class="br0">&#40;</span><span class="kw2">date</span> <span class="re5">-d</span> <span class="st_h">'yesterday'</span> +<span class="sy0">%</span>m<span class="sy0">%</span>d<span class="sy0">%</span>y<span class="br0">&#41;</span><span class="sy0">&amp;</span>quot;
    <span class="kw3">echo</span> <span class="re1">$yesterday</span>
<span class="kw1">elif</span> <span class="br0">&#91;</span> <span class="re1">$os</span> == <span class="st_h">'SunOS'</span> <span class="br0">&#93;</span>;
    <span class="kw1">then</span>
    <span class="re2">yesterday</span>=<span class="sy0">`</span><span class="re2">TZ</span>=GMT+<span class="nu0">24</span> <span class="kw2">date</span> +<span class="sy0">%</span>m<span class="sy0">%</span>d<span class="sy0">%</span>y<span class="sy0">`</span>
    <span class="kw3">echo</span> <span class="re1">$yesterday</span>
<span class="kw1">fi</span></pre></div></div></div></div></div></div></div>


<h3>Gnu Date</h3>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="bash"><pre class="de1"><span class="co0">#!/usr/bin/bash</span>
&nbsp;
<span class="co0">## Get Yesterday</span>
<span class="re2">yesterday</span>=<span class="sy0">&amp;</span>quot;$<span class="br0">&#40;</span><span class="kw2">date</span> <span class="re5">-d</span> <span class="st_h">'yesterday'</span> +<span class="sy0">%</span>m<span class="sy0">%</span>d<span class="sy0">%</span>y<span class="br0">&#41;</span><span class="sy0">&amp;</span>quot;</pre></div></div></div></div></div></div></div>


<h3>Powershell</h3>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="powershell"><pre class="de1"><span class="re0">$yesterday</span> <span class="sy0">=</span> <span class="br0">&#40;</span><span class="kw1">get-date</span> <span class="kw5">-format</span> mmddyy<span class="br0">&#41;</span>.adddays<span class="br0">&#40;</span><span class="sy0">-</span><span class="nu0">1</span><span class="br0">&#41;</span>
<span class="re0">$yesterday</span>.tostring<span class="br0">&#40;</span><span class="st0">'MMddyy'</span><span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>


<h3>Python</h3>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="python"><pre class="de1">&nbsp;
<span class="kw1">import</span> <span class="kw3">datetime</span>
today <span class="sy0">=</span> <span class="kw3">datetime</span>.<span class="kw3">datetime</span>.<span class="me1">today</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
one_day <span class="sy0">=</span> <span class="kw3">datetime</span>.<span class="me1">timedelta</span><span class="br0">&#40;</span>days<span class="sy0">=</span><span class="nu0">1</span><span class="br0">&#41;</span>
yesterday <span class="sy0">=</span> today - one_day
yesterday.<span class="me1">strftime</span><span class="br0">&#40;</span><span class="st0">'%m%d%y'</span><span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>


]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/coding/2011/08/get-yesterdays-date/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Normalize MAC address with Python</title>
		<link>http://codetwit.com/sysadmin/2011/08/normalize-mac-address-with-python/</link>
		<comments>http://codetwit.com/sysadmin/2011/08/normalize-mac-address-with-python/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 00:32:33 +0000</pubDate>
		<dc:creator>basketcase</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://codetwit.com/?p=361</guid>
		<description><![CDATA[In an earlier post, Scott did this in a simple shell script. I was curious if I could do it in Python since I am learning Python. Below is my first attempt. Watch for upcoming updated version. import sys &#160; if not sys.argv&#91;1:&#93;: mac = raw_input &#40;&#34;Enter MAC address\n&#34;&#41; print &#34;Mac is %s\n&#34;; % &#40;mac&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>In an earlier <a href="http://codetwit.com/sysadmin/2011/08/normalize-mac-address-for-dhcp-reservations/" title="Normalize MAC address for DHCP reservations" target="_blank">post</a>, Scott did this in a simple shell script.  I was curious if I could do it in Python since I am learning Python. </p>
<p>Below is my first attempt.  Watch for upcoming updated version.</p>


<div class="wp-geshi-highlight-wrap5"><div class="wp-geshi-highlight-wrap4"><div class="wp-geshi-highlight-wrap3"><div class="wp-geshi-highlight-wrap2"><div class="wp-geshi-highlight-wrap"><div class="wp-geshi-highlight"><div class="python"><pre class="de1"><span class="kw1">import</span> <span class="kw3">sys</span>
&nbsp;
<span class="kw1">if</span> <span class="kw1">not</span> <span class="kw3">sys</span>.<span class="me1">argv</span><span class="br0">&#91;</span><span class="nu0">1</span>:<span class="br0">&#93;</span>:
   mac <span class="sy0">=</span> <span class="kw2">raw_input</span> <span class="br0">&#40;</span><span class="st0">&quot;Enter MAC address<span class="es0">\n</span>&quot;</span><span class="br0">&#41;</span>
   <span class="kw1">print</span> <span class="st0">&quot;Mac is %s<span class="es0">\n</span>&quot;</span><span class="sy0">;</span> % <span class="br0">&#40;</span>mac<span class="br0">&#41;</span>
   <span class="co1">#sys.exit(0)</span>
<span class="kw1">else</span>:
   mac <span class="sy0">=</span> <span class="kw3">sys</span>.<span class="me1">argv</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>
   <span class="kw1">print</span> <span class="st0">&quot;Mac is %s<span class="es0">\n</span>&quot;</span> % <span class="br0">&#40;</span>mac<span class="br0">&#41;</span>
&nbsp;
<span class="co1">##I'm checking to see if someone is giving me in the right format</span>
maclen<span class="sy0">=</span><span class="kw2">len</span><span class="br0">&#40;</span>mac<span class="br0">&#41;</span>
<span class="kw1">if</span> maclen <span class="sy0">==</span> <span class="nu0">12</span>:
    <span class="co1">## converting to list, since strings are immuatable</span>
    maclist<span class="sy0">=</span><span class="kw2">list</span><span class="br0">&#40;</span>mac<span class="br0">&#41;</span>
    <span class="co1">## defining positions on list</span>
    positions<span class="sy0">=</span><span class="nu0">2</span><span class="sy0">,</span><span class="nu0">5</span><span class="sy0">,</span><span class="nu0">8</span><span class="sy0">,</span><span class="nu0">11</span><span class="sy0">,</span><span class="nu0">14</span>
&nbsp;
    <span class="kw1">for</span> i <span class="kw1">in</span> positions:
        maclist.<span class="me1">insert</span><span class="br0">&#40;</span>i<span class="sy0">,</span><span class="st0">':'</span><span class="br0">&#41;</span>
    <span class="co1">##joining list at the ','</span>
    newmac<span class="sy0">=</span><span class="st0">&quot;,&quot;</span>.<span class="me1">join</span><span class="br0">&#40;</span>maclist<span class="br0">&#41;</span>
    <span class="co1">## stripping ',' out and converting to lowercase.  </span>
    final12mac<span class="sy0">=</span>newmac.<span class="me1">replace</span><span class="br0">&#40;</span><span class="st0">','</span><span class="sy0">,</span><span class="st0">''</span><span class="br0">&#41;</span>.<span class="me1">lower</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
&nbsp;
    <span class="kw1">print</span> final12mac
&nbsp;
<span class="co1">##assuming that 17 characters will either have - or : in MAC address    </span>
<span class="kw1">elif</span> maclen <span class="sy0">==</span> <span class="nu0">17</span>:
    <span class="co1">##replacing - with : and converting to lowercase</span>
    mac17final<span class="sy0">=</span>mac.<span class="me1">replace</span><span class="br0">&#40;</span><span class="st0">'-'</span><span class="sy0">,</span><span class="st0">':'</span><span class="br0">&#41;</span>.<span class="me1">lower</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
    <span class="kw1">print</span> mac17final
<span class="kw1">else</span>:
    <span class="co1">## I'm telling them that if it isn't 12 or 17 characters, it has X chars</span>
    <span class="kw1">print</span> <span class="st0">&quot;There are only %s characters&quot;</span> % <span class="br0">&#40;</span>maclen<span class="br0">&#41;</span></pre></div></div></div></div></div></div></div>


]]></content:encoded>
			<wfw:commentRss>http://codetwit.com/sysadmin/2011/08/normalize-mac-address-with-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

