Linux, programming, computers and life

August 20, 2007

arrays in awk

Filed under: CLI, programming, awk

awk is even better than i thought it is. It has arrays. Recently i needed to examine a log file, which includes mixed output from several threads, and to find 2 latest strings of each thread. I didn’t know how to do it, till a coworker mentioned to me about those arrays.
The script is extremely simple:

cat my_log_file.txt | awk '{arr[$2, 1] = arr[$2, 0]; arr[$2, 0]=$0} END { for (s in arr) print s" : "arr[s] }'

Some explanations:

  • {arr[$2, 1] = arr[$2, 0]; arr[$2, 0]=$0}
    - an operation which is performed on every line. Column 2 is the thread number. I keep in array with index [threadNumber,0] the last line and the line before last in index [threadNumber,1]
  • END { for (s in arr) print s" : "arr[s] }'
    - the final operation - print all the array with it indexes

Technorati Tags: , , , , ,

August 12, 2007

boost writers are geniuses

Filed under: programming, c++

I’m currently rewriting some python code in c++, due to performance problems. I needed a simple parser and i found spirit which is part of boost. I must say wow WOW. I must learn boost. It’s simply great. While I’m pretty sure it will not be possible to use it at work due to conservative nature (with respect to code and tools) of the management here, it’ll surely give me some ideas :) .

Technorati Tags: , , ,

August 5, 2007

mobile jabber client

Filed under: life, internet

I got a new phone, and i decided to pay to my cellular provider for wap access. I mainly wanted to have jabber access from the phone to see how is it to be always online… Well, there are a lot of J2ME open source jabber clients, but i need one that works over http… jimm does it, but it’s ICQ only. Talkonaut works great, but i really prefer open source application if i can find one.
Suggestions?

Technorati Tags: , , , ,

Get free blog up and running in minutes with Blogsome
Theme designed by Gary Rogers