The writings of Peter Stuifzand

Weblog: bash

A few days ago I had to create list of email addresses sorted on the domainname. All addresses with the same name should clump together. Being a Perl programmer, I quickly wanted to write a Perl script to sort this list of data. Then I tought, why not use Vim to look at the intermediate steps and do it with filtering. The following is the result.

:%!perl -pe 'm/\@([-\w]+)\./; $_="$1\#$_";'
:%!sort
:%!cut -d\# -f2

The first line parsed the domain from the data and pastes it in front of the orignal, seperating it with a '#'. The second line obviously sorts the new list. The final line removes the domain that I put in front. This leaves a list of the originals.

:%!perl -pe 'm/\@([-\w]+)\./; $_="$1\#$_";' | sort | cut -d\# -f2

This will do it in one line.

A few days ago I created two new aliases for places I connect to with ssh. Both locations have a three character alias now.

To use the aliases I created a new file called ~/.aliases. This file contains all the aliases I use. This file should be sourced in the ~/.bashrc file with the following command.

source ~/.aliases

Then add the following line to the ~/.aliases file.

alias realias='$EDITOR ~/.aliases; source ~/.aliases'

Restart bash and type realias. It will open an editor to the ~/.aliases file and source it when your done.

The ssh aliases look like this. You should change hostname1 to the new of your server.

alias ss1='ssh hostname1'

Another useful alias is lt. It shows the files in order of modification. The files that were changed last, will show up at the bottom.

alias lt='ls -lrt'

Are there any aliases that you like to use?

View archived entries