For some reason Unity in Ubuntu 16.04 and the SublimeText deb package don’t play well together and the integration is not quite right – for one the launcher says “UNREGISTERED” even after entering a valid licence key, and SublimeText does not appear in Nautilus context menu as an option to open files. Here’s the workaround for this issue.
Great post on Stack Exchange, How to correctly add a path to PATH?.
Lots of issues with Network Manager in Ubuntu 16.06 LTS, in particular connecting to wifi after suspend/resume. Restarting the Network Manager service seems to work for me.
1 |
sudo systemctl restart network-manager.service |
Here’s the fix for a problem where Nautilus shows hidden files by default.
$dconf-editor
- org -> gtk -> settings -> file-chooser
- Uncheck show-hidden
- Close Nautilus and open again
I have just installed the Crayon Syntax Highlighter plugin on this blog. Obviously a lot of the posts that I put here contain code snippets, so this great plugin will make that a little neater with feauters such as line numbers toggle, syntax highlight, copy into clipboard and many more. Over time I hope to update the existing content on the site to make use of the plugin.
In this post we look at how text data can be transposed in a shell script. Suppose you have a comma-delimited text file (csv) which looks like this:
2014-10-01,Reading1,20.3
2014-10-01,Reading2,21.5
2014-10-01,Reading3,24.0
2014-10-01,Reading4,22.2
2014-10-02,Reading1,20.5
2014-10-02,Reading2,21.5
2014-10-02,Reading3,24.1
2014-10-02,Reading4,22.4
2014-10-03,Reading1,20.5
2014-10-03,Reading2,21.7
2014-10-03,Reading3,24.2
2014-10-03,Reading4,22.5
…and so on. Perhaps this is a set of sensor readings over a period of time, and in this case there are four readings per day. For further analysis it might be more suitable to store each date on a single line with the four readings as columns. In other words we want to transpose rows to columns, i.e. pivot the values on date. The file should look like this:
2014-10-01,20.3,21.5,24.0,22.2
2014-10-02,20.5,21.5,24.2,22.4
2014-10-03,20.5,21.7,24.1,22.5
Since this needs to process multiple input rows of to produce one output row, sed will not be suitable. Instead we need to use awk. The following tiny script will do the trick.
1 |
$awk -F, '{val = val "," $3; if( NR % 4 == 0 ) { print $1 val; val = "" } }' |
Now, what exactly is this doing? First, we need to specify that the file is comma delimited, which is what -F,
does. Next, the main principle is that the code stored between the curly brackets will be executed individually for each row, however a session (including variables) is maintained throughout the execution of entire input. So val
is a variable into which we are storing the third field on each row ($3
) prepended by a comma. The if statement checks whether the row number (NR
is a special built in variable which holds the number of the row being currently processed) is divisible by four (%
is the modulo function, as in most languages). If yes, we print the date which is the first column ($1
) as well as the val
variable which now has the values from the previous three rows as well as this one, separated by commas. The variable is then reset.
Obviously, we are making an assumption here that the data is uniform, i.e. that there are exactly four readings available for each day; otherwise the script would be a little more complex.
Suppose you have a monthly process to archive some data such as log files etc. Each month a separate archive file is created, and so after a few months you will have several archive files – for example as shown below:
archive.2014-08.tar.gz
archive.2014-09.tar.gz
archive.2014.10.tar.gz
Now if you wish to extract your data from all three files, you could run individual commands such as:
1 2 3 |
$tar -zxvf archive.2014-08.tar.gz $tar -zxvf archive.2014-09.tar.gz $tar -zxvf archive.2014-10.tar.gz |
This works fine. However the following won’t work if you want a one-line which does them all in one short:
1 2 3 |
$tar -xzvf *.tar.gz tar: archive.2014-09.tar.gz: Not found in archive tar: archive.2014-10.tar.gz: Not found in archive |
Basically the way that tar command works, if more than one filename (or an expansion) is passed as an argument, it will look for the second, third, etc. files
1 |
$ls *.tar.gz | xargs -n1 tar -xzvf |
FPrint is a PPA with packages for fingerprint-based authentication. Website includes good documentation on how to install and set it up.
This is a great one-liner which removes old kernel images and frees up space in your boot partition:
1 |
$sudo apt-get purge $(dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve "$(uname -r | sed -r 's/-[a-z]+//')") |
This comes from the top answer to a question on ask ubuntu.
Here’s an article on Lego’s Land on how to reorder accounts in the left pane of Thunderbird.