Wednesday, 15 December 2010

changing locale

Working with real (decimal) numbers can be problematic when changing between computer with difference language (locale) settings. For example, in the Netherlands a comma is used for the decimal, i.e., sqrt(2) becomes something like 1,4142. In the US a dot is used, as is in most? scientific fields. So, sqrt(2) becomes 1.4142. Input files made up in one locale will be misread in another locale.

Changing to US locale is easily done:
export LANG=en_US.UTF-8
setenv LANG en_US.UTF-8

Thursday, 9 December 2010

AWK - get last field

When I generate output from my programs, it is frequently accompanied with some textual information. For example, an output line could read as
Total time: 1234.5
Avoiding tedious copying and pasting, a simple awk command can get the last field from the lines:
awk '{ print $NF }'