Wednesday, May 23, 2012

The Usual Intro

I want this blog to be no-nonsense... which makes me wonder why I am evening writing this intro blog post.  It's a complete waste of time right?  We all know why this blog is here.  Software development, Linux, computing, CLI joy, hardware choices, and the favorite coffee of the moment.

I am just going to say right off the bat that I may not be able to resist putting up a short post of my current coffee of the moment.  I am a coffee fanatic and it is a big part of my day, my mind, and hence my software development.  I also really love chai tea... but not as much as coffee.

Another important thing to note...  I am (generally) a JOATMOS - Jack Of All Trades Master of Some.  So that means I am not an expert in everything.  I am being pretty flexible with comments.  So just a warning:  no need to pounce on something I post that seems simple to you or obvious or basic.  This is not a blog about all things mind-blowing.  I am hoping it is about all things neat and interesting.  Like for example...

Today I needed to find out what was causing a build to fail in an environment that is still very new to me.  When running as I normally do when developing, the make script assembles a seriously long command string with lots of options... all on one super long line that fills the screen.  Much larger than this Lorem Ipsum example:

Mauris -velit -mauris -hendrerit -quis -ultrices -in -congue -eget -elit -Sed -urna -ligula -vestibulum -eu -pulvinar -id -condimentum -ac -leo -Sed -elit -magna -dignissim -ut -dictum -non -elementum -et -nulla -Nunc -eu -mi -eu -nulla -fringilla -condimentum -Nulla -nisi -felis -pulvinar -eu -viverra -quis -tristique -vitae -diam -Phasellus -non -laoreet -felis -Pellentesque -lacus -elit -sagittis -vel -lacinia -sit -amet -molestie -a -odio -Phasellus -suscipit -sapien -quis -molestie -pharetra -purus -mi -tempor -eros -et -aliquam -mi -dolor -quis -velit -Integer -in -ligula -felis -eget -mattis -dolor -Nam -sit -amet -ante -elit -vel -feugiat -arcu -Mauris -nibh -mi -iaculis -non -gravida -id -elementum -at -arcu -Suspendisse -dapibus -consequat -convallis -Sed

But it works, so who cares, right?  Well, another form of building (say... building a release) uses a similar command string and it looks just as long and insane.  But the release version is not working.  Which switch is missing?  The log file records the actual executed command string so I have it in a text file all on one giant line.  I run both methods and save the logs.  Now I want to use the diff commands to see what is going on.  But diff is not good at working with giant lines, so now I want to break it up, one switch per line.  I use vim/gvim.  (Queue the flame wars.)  So now I want to put a return character in front of every " -switch arg".  I could be a grunt and do it by hand, but I am not kidding you when I say it's wrapping about 30 times with gvim fully maximized on my 1920 pixel wide display.  I refuse to do that - not to mention I would feel like a hack doing that by hand.  So here is the search/replace command I used in vim to do that:

:s/\ -/ \r-/g

In an instant I have this:


Mauris
-velit
-mauris
-hendrerit
-quis
-ultrices
-in
-congue
-eget
-elit
-Sed
-urna
-ligula
-vestibulum
-eu
-pulvinar
-id
-condimentum
-ac
-leo
-Sed
-elit
-magna
-dignissim
-ut
-dictum
-non
-elementum
-et
-nulla
-Nunc
-eu
-mi
-eu
-nulla
-fringilla
-condimentum
-Nulla
-nisi
-felis
-pulvinar
-eu
-viverra
-quis
-tristique
-vitae
-diam
-Phasellus
-non
-laoreet
-felis
-Pellentesque
-lacus
-elit
-sagittis
-vel
-lacinia
-sit
-amet
-molestie
-a
-odio
-Phasellus
-suscipit
-sapien
-quis
-molestie
-pharetra
-purus
-mi
-tempor
-eros
-et
-aliquam
-mi
-dolor
-quis
-velit
-Integer
-in
-ligula
-felis
-eget
-mattis
-dolor
-Nam
-sit
-amet
-ante
-elit
-vel
-feugiat
-arcu
-Mauris
-nibh
-mi
-iaculis
-non
-gravida
-id
-elementum
-at
-arcu
-Suspendisse
-dapibus
-consequat
-convallis
-Sed


Now I have all the switches on their own line.  Beautiful!  And now I can use the diff command to clearly see the differences between the commands.  For those who are interested, I found the culprit within seconds of scanning the diff file.  That was a good feeling.  I have many more grep, sed, wc, etc command combinations that I would love to share over time.  The past 7 years I have been a consulting engineer working with a large number of ASIC development customers who all work in Linux.  I have had to get pretty creative on the command line to debug and develop some interesting scripts.  Now I am in a development role getting more into the software development side of things and completely loving it.

So back to my intro.  That is what I am talking about.  I'm not changing the world.  But maybe there is a tip that will help your work go a little smoother and give you that good feeling somewhere in your day.