Monday, February 6, 2012

How to grep for NULL char

Was trying to extract some FIX messages from log files, and more precisely filter out a number of messages like heartbeat. My initial thought was to do something like that:

cat fixlog.log | grep '\[8=FIX.' | tr '\1' '|' | grep -v '\|35=0'

That works fine, except it's a little bit wasteful. What this command above does is, replace all the null character (that are used as delimiter in FIX messages) by "|". So that got me thinking how I could filter out those without having to replace anything. My first idea was:

cat C20120203.log | grep '\[8=FIX.' | grep -v '\00135=D'

That didn't work because grep was interpreting \001 as a back reference. Several variants later (among which the use of sed) and some constructive goggling made me understand that the the problem wasn't coming from grep but from bash and here's the proof.

If you type the following (under linux):
$ echo '\001' | hexdump -C
00000000  5c 30 30 31 0a                                    |\001.|
00000005

The trick is to tell bash do some quoting (escaping), and you do that by prefixing the string with $:
$ echo $'\001' | hexdump -C
00000000  01 0a                                             |..|
00000002

So putting it all together the original command above becomes:
cat fixlog.log | grep '\[8=FIX.' | grep -v $'\00135=0'
The mechanism allow you to grep for any arbitrary ASCII character.

Friday, November 25, 2011

How to use easy_install through a proxy

You first need to make sure that the shell variable http_proxy is defined:
$ env | grep http_proxy
http_proxy=http://your-proxy.com:yourport


On this done you can run simply run easy_install as follow:
sudo -E easy_install your_package
The "-E" parameter for sudo preserves your environment (namely variables) which is not the default behavior.

Tuesday, November 22, 2011

How to fix windows 7 install stuck at step "Finalizing your settings"

While trying to install windows 7 on my shiny Macbook, after the whole ordeal i had went through (See here and here for more details), I finally had the install going and was at the last step.
By last step I mean my computer had already rebooted several times, went through "Setting up your computer for first time use", and was at the step "Finalizing your settings".
Unfortunatly this last step took forever. By Forever i mean, after leaving my computer at it the whole night, was still stuck there in the morning.

Monday, November 21, 2011

Install Windows 7 with boot camp on mac (Part 2)

Small resume from Part 1:
  • I am the (un)happy owner of a late 2008 Macbook Pro
  • My super Drive is DEAD
  • I have Mac OS X Lion installed on my mac
  • For whatever (foolish) reason I want to install Windows 7 on a Bootcamp partition
  • I used Bootcamp 4.0.1

In the guide below i will explain how i managed to (finally) install Windows 7 on my bootcamp partition. But before we go further, some important warning. This whole procedure is at best dangerous, and is not for the faint hearted. It can possibly screw up your disk, follow it at your own risk. I strongly advise that you read this guide completely before starting this whole procedure by yourself. Now that you've been warned, let's get started.

Windows 7 with boot camp on macbook late 2008 (Part 1)


In this serie of articles, i will describe the steps I followed while trying to install a Windows 7 in Boot Camp. I will try to make this guide as detailed as possible in hope it'll be helpful to other people. But before i dive in a bit of context, that has its importance.

My computer is a MacBook Pro of late 2008, whose Superdrive is unfortunately dead. Which meant i was not able to simple put in the DVD install of Windows 7 into my Superdrive into my MacBook, which left me with trying to install it from a USB boot disk. Unfortunately, my Mac being from late 2008, it means that usb boot disk was out of the question, which i only discovered after trying to the steps below.