commandline

Eternal bash history

After starting to use the bash, you quickly realize bash history is an invaluable asset. You can quickly search and find a previous command in order to remember when and what you have done. I was using a primitive way to archive the history with which I accumulated history of commands since 2008. The primitive setup has two parts. First part is a cron job: 0 13 3,11,24 * * /bin/cat ~/.

List of terminals with working folder names

From time to time, I had many terminal tabs open and wanted to see the list of terminals along with working folder names. Finally, I fed up with the issue tried to find a solution. After fiddling with some code, here’s the function that I added to .bashrc file tty-list() { ps aux --sort=start_time | grep "pts/" | grep [b]ash | awk -F" +" '{print $2"\t"$7}' | while read PID PTS; do echo -n -e "$PTS""\t"; readlink -f /proc/$PID/cwd; done ; } In terminal, tty-list command lists the pts number and working folder name as shown below:

Transpose a matrix with perl nested map

Here’s the matrix that we’ll be using: $ paste <(seq 1 5) <(seq 12 16) 1 12 2 13 3 14 4 15 5 16 Now, let’s use a perl one-liner with nested maps to transpose the matrix: $ paste <(seq 1 5) <(seq 12 16) | perl -ane 'push @matrix,[@F]; END { print join "\n",map {$row=$_; join"\t",map { $matrix[$_][$row]} 0 .. $#matrix } 0 .. $#{$matrix[0]}; print "\n" }' 1 2 3 4 5 12 13 14 15 16 I got the idea from this blog post, but I slightly modified it so that you don’t need to make a copy of the transposed array (to save memory)

Extract intervals from an array of numbers

Let’s assume you have an array of numbers and you want to extract intervals from this array. For example, from such an array: 2,3,4,5,8,9,10,11,12,15,18,19,20 you should be getting (2-5), (8-12), (18-20) as intervals. More bioinformatic case: Let’s assume you ran samtools pileup format and want to extract intervals from the genomic coordinates that has at least one hit.

Plot one-liner generated data with gnuplot

In this post, I’ll demonstrate how to use gnuplot in a one-liner. We’ll use the pipe but unfortunately you cannot pipe raw data to gnuplot directly (as far as I know). The piped data should contain basic gnuplot commands on top. So, we’ll use the following template: very-complicated-data-generating-commands | sed -e "1i\plot '-' " | gnuplot -persist If you’re interested in quickly see how this works, try something simple:

bash completion for scp

I have been looking for a solution for broken bash_completion for scp command. I was thinking my ssh was not configured correctly for password-less login. But I just found out that bash completion is broken for Ubuntu 9.10. If you are suffering from same symptom, please read this article for fix.

Retrieve WP categories from commandline

Posting to WP from commandline is great. Before I post it, I need to lookup available categories so that I can categorize the new post correctly. To prevent a visit to WP admin GUI, I used the same Perl module for posting to retrieve available categories. Below is the code. I hope it helps you too.. use WordPress::XMLRPC; my $o = WordPress::XMLRPC->new({ username => 'username', password => 'password', proxy => 'http://yourblog-address/xmlrpc.