Bob Mesibov's articles

Finding changes in a sorted list: a trick

Think of a phone directory listing with a lot of Browns followed by some Brownes, Brownings and Brownleys. Is there a simple way to identify the places in the sorted list where Brown changes to Browne, Browne to Browning and Browning to Brownley?

If you're a programmer, you've probably just thought of an 'if, then' test for items in the list. If you're an AWK-lover (like me!) you may have started thinking about the getline option.

There's another and more interesting way to do this job on the GNU/Linux command line, as explained below.

Save time with AWK print

Since discovering AWK last year I've been using it regularly with tables of data. It seems like everything I do with those tables is faster and easier with AWK on the command line than the same jobs would be with spreadsheet software.

Below are a couple of examples that demonstrate the handiness of the print command in AWK. If you've never used AWK before, see the links at the end of the article for a quick introduction to the basics.

A very tiny GIS

quickplot is a fast, interactive 2-D plotter. All it needs to do its job is a text file with x and y points in a list. If those points are longitude and latitude in decimal degrees, quickplot works like a simple GIS program, with some surprising capabilities.

This article explains how I set up quickplot to do species mapping for Australia. For most of my mapping work I use qgis and Google Maps/Earth, but quickplot is handy for quickly making simple maps and zooming in on details. With an executable size of only 453 kb, quickplot is the tiniest and fastest GIS I know.

CoPa: 2 scripts for LibreOffice Calc and 1 for the kid in you

In a previous article I introduced the idea of modifying text between copy and paste in Linux, using a 'CoPa' script based on the xclip utility. Please refer to that article for the basic ideas.

Here I demonstrate two handy CoPa scripts for spreadsheets, and a simple coder/decoder for (very!) low-level encryption of email text and other messages.

Split a spreadsheet into multiple files with the GNU/Linux command line

Have you ever wanted to split a spreadsheet into several spreadsheets according to the contents of a particular field? For example, you might have a music tracks spreadsheet with an 'artist name' field, and you want separate spreadsheets for each artist, with the usual field names along the top of each new spreadsheet.

You can split a spreadsheet by copying and pasting the different sections into new spreadsheets if there aren't many records. If there are lots of records, this manual approach can be pretty tiring. For splitting very large spreadsheets, most users turn to special stand-alone programs (in the Excel world) or fairly complicated macros (Excel, Open/LibreOffice Calc).

I split my spreadsheets using the GNU/Linux command line, as explained in this article. It's another of my trademark ugly hacks, but it works well and the command line steps can be combined into a script which runs fast and reliably.

Firefox and Iceweasel can 'mailto' with Sylpheed and Claws Mail

Some webpages contain email links. If you right-click on the link in most Web browsers, a menu appears that lets you copy the email address to the clipboard (first screenshot). You can then paste the address into the To field of a new email message.

In recent versions of Mozilla's Firefox browser, you can also left-click on the link and get some action. If Mozilla's Thunderbird is your default mail program, a Thunderbird 'compose' window may appear with the To field automatically filled in. This article explains how you can get the same automatic result under Linux with the excellent open-source mail programs Sylpheed and Claws Mail. The method also works with Iceweasel, which is the rebranded Firefox packaged with Debian GNU/Linux.

Build a scientific names dictionary for LibreOffice

LibreOffice only knows how to spell a few scientific names, and the more scientific names you use in a Writer document, the more your pages fill up with squiggly red underlining – indicating misspelled or unrecognised words (see main image). You can add scientific names to LibreOffice's spell checker using the application's spelling dialog box, but only one word at a time.

Is there an easier way? Yes. This article explains how you can save a lot of time and effort by adding hundreds of scientific names to the spell checker all at once.

Color picking made simple

If I see a color on my computer screen that I'd like to use somewhere else, I want to know that color's hexadecimal code. Conversely, if I see a color's hex code, I want to know what that coded color looks like on-screen.

Some time back, I wanted an application that does both those jobs simply in Linux. The best tool I found was gcolor2, described below. It's great for finding hex codes, but it doesn't display colors in a large enough 'swatch' to suit me. To do that job I wrote a simple script, also described below.

Compare two images easily with Geeqie

In my entomological work I often need to compare two images of bugs side-by-side.

Comparisons are surprisingly hard to do with either of the image viewers I normally use, namely Eye of Gnome and Ristretto. First I open two instances of the viewer and adjust their window sizes and positions for easy side-by-side comparison. I then open one image in one viewer window, and the other image in the other window. If I want to zoom in or out, or pan across the images, I have to do this independently in each viewer window. If I don't save this two-instance arrangement on a dedicated workspace using 'Save session on exit', I'll have to repeat the setting-up next time.

Comparisons are much simpler in Geeqie image viewer, which is now in most of the Linux distribution repositories. I first heard about Geeqie in 2011 when it was featured in a glowing online review. I hope this article adds to the glow.

Convert XML to CSV the ugly way using Unix utilities

I recently wanted to export my email address book from Sylpheed email client and import it into my Gmail account. Unfortunately, Gmail wants to import contact lists as CSV files, and there isn't an export-address-book-to-csv feature in the otherwise wonderful Sylpheed. Worse, the Sylpheed address book is in XML format, and XML-to-CSV conversion isn't straightforward.

Warning: What follows contains code that may offend real programmers. The code works but it's pretty simple-minded, and if you're a real programmer and not a hobbyist hacker like me, you may not want to read any further.

Checking a website for incorrect links

When you build or update a website, it's a good idea to check that all the links on your webpages are OK. An excellent tool for doing this under Linux is the aptly named linkchecker, a GPL-licensed, command-line program.

However, 'OK' has more than one meaning. While linkchecker can check the URL you specify to see if it's properly formed and not broken, it can't tell you if the link points to the wrong URL.

A spreadsheet jukebox

My wife has a huge collection of Scottish country dancing music on her Linux laptop – more than 2000 dance tracks. Details of all tracks are recorded in an OpenOffice Calc spreadsheet.

She asked me, "Could you make the spreadsheet into a jukebox, so that I could do a filtered search for a suitable track, then just click on the track to have it play?" The answer was yes, but it took a while to get there!

Write a simple launcher using Zenity

Nowadays, we mostly interact with our computers using a Graphical User Interface. The operating system as a whole uses several elements of the GUI to make the user experience more human-like. Can users get to unleash some of the GUI's power? The answer is yes: welcome to Zenity, a GTK+ application that works in GNU/Linux, BSD and Windows. In this short article I will show you how to create a simple script that interacts with the user using the GUI.

Basics of mapping with KML

Two of the most useful free (as in beer) software applications from Google are Google Earth, which runs on your computer, and Google Maps, which runs as a Web service. You can use both Google Earth and Google Maps to plot your own points, lines or shapes on an interactive map. You can also annotate these things with informative details. Unfortunately, the user interfaces provided by Google for doing this kind of DIY mapping are... well, clunky. They're slow, especially if you have a lot of items to add to a map.

Programming effective reminders in GNU/Linux

There are some nice sticky-note applications for Linux, and they're good places to write down reminders, like Ring Fred or Pick up a litre of milk.

Unfortunately, sticky-notes are no help to me at all. I'm often forgetful, and I'm more than likely to shut down my computer without checking to see if I've written a note to myself. To get around this problem, I wrote a couple of very simple scripts, each launched by an icon on my Xfce panel.

Find duplicates and originals in a spreadsheet using the Unix command line

Sometimes, you need to find and group together the replicated records in a spreadsheet. There are several different ways to identify duplicated records (see this tutorial for a good one), but what I wanted was something a bit more fancy. I wanted not just the duplicates, but each original record as well. Furthermore, I wanted any replicates (original + duplicates) grouped together in neat little sets in the spreadsheet.

Here is how I did it using the Unix command line.

Measures on the command line

In an earlier article I promised to demonstrate more 'magic words' for the command line. All you do is open a terminal, enter the magic word, hit Enter – and cool things happen! The magic word this time is units. The GNU Units program isn't installed by default in most Linux distributions, so you'll probably need to install it from your distribution's repository. Also, until you get to know GNU Units, I recommend that you enter units -v (v for verbose) on the command line. This makes the output a little more easy to understand.

The GNU Units program converts quantities from one unit system to another.

Pages

Subscribe to RSS - Bob Mesibov's articles