Print Particular Lines of a File Using SED

Say you want to print the lines 3 and 7, and all lines from 11 to 15 of a text-file. The following SED one-liner will do for you

sed -n -e '3p' -e '7p' -e '11,15p' textfile.txt

Anycom Bluetooth USB Adapter on Windows 7

For the first time I could personally sense the effects of the economic crisis. The manufacturer of my Bluetooth device ANYCOM USB-200, the Germany-based ITM Technology AG is insolvent. Immediate effect for customers like me: No more driver updates and their general unavailability on the homepage.

Here is the good news for everybody who wants to use an ANYCOM Bluetooth USB adapter (200, 250, 500) on Windows 7. The Vista driver runs just fine under Windows 7. And I got the driver ( “anycom-bluetooth-usb200-250-500-vista-v6-1-0-4700.exe”). If anybody needs it, feel free to send me an email (see About). It may be worth noting that Windows 7 complains about not being able to correctly install Bluetooth devices like a headset (Plantronics Voyager 510 for me), while in fact you you only need the correct driver for the adapter.

Update: After brisk demand I decided to allow you to download the driver directly from this website. Of course, no warranty whatsoever provided.

Working with a List of Tuples in Shell Scripting

Several people have recently asked me whether or not it is possible to use tuples in their shell script. One example is running a program with a varying set of parameters. Since they often did not find a good solution, they began to formulate their problem in a higher-level scripting language like Ruby. Surprisingly, you can accomplish the same task easily with simple shell scripting (supported by bash, zsh,..). Consider the following (semi-stupid) example

#!/bin/bash
paramset="foo.txt 1 --with-graphics
bar.txt 8 --no-graphics
flock.txt 4 --with-graphics"

echo "$du" | while read file p1 p2 ; do
./myProgram $file -t $p1 --verbose $p2
done

We here run the program myProgram three times (for each line in the multi-line string). Every line contains three white-space separated values (words), to which we assign the variable names file, p1, p2 in the loop header. Note that the last variable (in this case p2) always contains all remaining words of a given line if there are more words then variables.

The set of parameters can also be stored in a file. In that case, replace the loop header with cat params.txt | while read file p1 p2 ; do. If the script is not working properly, examine the Input-Field-Separator (IFS) variable, which should be set to IFS=" ".

Scotland Photos

IMG_3409 Here are some impressions from my recent trip to the Scotland. It really is a lovely place to travel. The route included places like Stirling, Fort Williams, Isle of Skye, Glenfinnan and more.

Read more »

Inline Figures in Org-Mode Paper Drafts

Writing a paper often comes along with a problem known as information fragmentation: figures, tables and the respective data sources related to the paper certainly are somewhere on your hard disk – but where? How did I name the file with the data-points again? And, the heck, which commands did I use to create that fancy plot? But chill, there is a way to avoid the joyless seeking and re-finding. At least if you draft your papers in org-mode, as I described in a recent post.

Read more »

List Only Subdirectories for Shell Scripting

I like to have the following snippet in my .zshrc (or .bashrc) for convenience

alias lsd="ls -l|awk '/^d/ {print \$9}'"

It displays all subdirectories underneath the current directory. The goodness in this variant is that it gives you the pure names and that you can use it in loops without hassle :

for d in `lsd`; do
mv $d/resultfile.dat $d_result.dat;
rmdir $d;
done

Finding out where your Program Crashes with the Emacs GUD

This post describes a very, very elementary debugging skill. Yet, I could not find any concise tutorial about it on the web. So, here we go!

Assume you’re developing a small software under Linux, maybe using C or C++ and the GCC compiler. Testing your program, you find that it crashes with an error (segfault, assertion, …). How do find the cause for this crash rapidly? How can you back-trace the error?

First, compile your program again adding the option “-g” (or “-gstabs“). The compiler (e.g. g++) will now include information necessary for debugging into your binary. Start Emacs and invoke “M-x gdb“. As parameter, enter the full path of your executable. You end up with something like “gdb --annotate=3 ~/myProject/myProgram“. In the newly opened buffer, set the commandline parameters as for example in “start --verbose-mode inputfile.dat“. Simply append the program options you normally use after “start“.

Run the command “c” (=continue). Your program will start – and crash. Now, invoke “M-x gdb-many-windows“. You will see the steps leading to the function that caused the crash in the window “stack frames”. By clicking on each of the steps, Emacs will directly navigate to the respective source code block, enabling you to trace the cause of the error. Find a more extensive tutorial here.

Economic Crisis coming faster than Great Depression

Since weeks  the media is reporting about the severity of the current economic crisis, comparing it with the Great Depression (GD) that began 1929. However, to me this seemed like a historic exaggeration since I couldn’t really rediscover the severe effects of the GD in the current crisis. However, I now found some figures that changed my mind.

In this article, the authors compare different economic metrrices of both times. The astonishing image that emerges is that the current crisis has already reached a great deal of the intensity of GD, but much faster. For example, we have already reached about 70% of the decrease in stock market value and about 35% of the decrease in world industrial output compared to the worst values during great depression. I find that a quite surprising result considering  the known social and political consequences of the GD. (Figure courtesy of Zeit Online)

Stock Market Comparison (Zeit Online Graphics)

Stock Market Comparison (from Zeit Online)

Including Math Formulas Into Emails

Today I stumbled over a very neat extension for the email client Mozilla Thunderbird. It allows you to include LaTeX style formulas into your email. Simply write down the formula enclosed in $$’s, e.g. $$\alpha = 5$$. Hitting a button will then convert all formulas into images and thereby allows you to send the email to any collegue that uses a HTML-understanding email client. Find the “Equations” extension here.

Online Memorizing Revisited

In december, I wrote an article about spaced repetition systems for learning vocabuly and other facts. The both web- and desktop-based tool Anki turned out to be particularly suitable for our purposes (see older post). One requirement was the ability to instantly share entered facts among a group of people, which interestingly was problematic for all tested tools.

We now found out that this feature is no poblem at all with Anki, which allows to subscribe to facts-sets (decks) of other people. This process is designed such that changes to shared decks propagate (see this discussion). In other words, once you subscribe to a deck, you will receive both corrections of existing facts and newly added facts. However, facts will not be deleted. So, just do as follows to get complete and instant sharing of facts among a group. One person -let’s call him master – sets up an initial deck and sends the share-key (to be found under Decks->share in the webinterface) to all other people in the learning group. Each of them subscribes to the master’s deck and sends his or her own share-key back to the master. The master now subscribes to all other decks. In effect, each group member can add and modify facts that will propagate to all other members. Perfect!