Linux DevCenter    
 Published on Linux DevCenter (
 See this if you're having trouble printing code examples

Living Linux

Contact Managers


Loosely put, a "contact manager" is a piece of software that helps you keep track of information about people you may need to contact in the future. In the past, people often called the physical version of these things a "rolodex," which incidentally was a brand name for the Cadillac of such contact managers, the circular Rolodex file that sat atop the desk of every successful 20th century businessman. I hear that many people use devices like this even today; in this week's column, I'd like to show how it can be done on Linux systems with faster search times and much less desk space.

Keeping a free-form address list

This is the simplest way to keep names and addresses in Linux.

You can keep names and addresses in a text file as a free-form address list; to find an entry, use the search capabilities of tools like grep, text editors, and text pagers such as less.

What's nice about such lists is that you don't have to keep the same information or format for each entry -- one might contain just a name and phone number, another a complete mailing address, another a name and e-mail address. With a free-form address list, each entry contains whatever information you want in the format you want. Separate the entries with a delimiter line of your preference, like "###" on a line by itself.

For example, suppose you have such a text file, rolo, containing three entries:

John Dos Passos
1919 America Ave.
New York City


Scott F. - 602 555 1803
(don't call after 12)


T. Wolfe's new email has changed.
The new one is:

Notice that each entry contains varied information, and in no particular format. That's the benefit of a free-form list -- you don't have to type the entries in any particular order, and you're not bound by a given set of "fields"; you can even cut and paste text into it from e-mail, the Web, or other windows.

Searching a free-form address list

There are several ways to find text in such a file. Suppose, for example, you want to contact your friend Scott, and you need his telephone number.

To output the line in the file containing the text "Scott", regardless of case, type:

$ grep -i scott rolo

The program will return

Scott F. - 602 555 1803

This works nicely when the information you need is on the same line as the information you search for -- here, the name Scott is on the same line as his telephone number; however, the output didn't show the warning that appears on the next line in the file. And what about when the term you search for and the information you need are on adjacent lines?

Use the -C option with grep to output two lines of context before and after matched lines.

To output all lines matching the text "olfe" with two lines of context before and after the matched line, type:

$ grep -C olfe rolo
T. Wolfe's new email has changed.
The new one is:

Another way to search such a file is to open it as a buffer in Emacs and use any of the Emacs search commands on it. The Emacs "incremental-search" function, C-s ("control-s"), is very useful for such files. If you type the characters to search for in all lower-case, Emacs matches those characters regardless of case.

For example, to search through the current buffer in Emacs for the first entry containing the text "new york," regardless of case, type:

C-s new york

If you do such a search on a large file and the first result is not the record you're looking for, just keep typing C-s until the right one is matched.

So to search for the next entry containing the text "new york," regardless of case, type:


You can repeat this operation as many times as you wish to cycle through all places in the entire buffer where the text "new york" appears.

Keeping a contact manager database

The Insidious Big Brother Database is a contact manager tool for use with Emacs, and it's compatible with all of the Emacs email and news readers. It stores contact information in "records" and allows you to search for records that match a regular expression as well as records whose particular fields match a regular expression.

There are several ways to add a record to the database. Use the "bbdb-create" function to manually add a record (when you run this command, bbdb prompts you to enter the relevant information for each field). When in a mail reader inside Emacs, type : to display the record for the author of the current message; if there is none, bbdb asks whether or not one should be created.

To manually create a new bbdb record, type:

M-x bbdb-create

To make a new bbdb record for the author of the current email message, type:


Use the "bbdb" function to search for records -- it takes as an option the pattern or regular expression to search for.

To output records containing the text "scott" anywhere in the record, type:

M-x bbdb

There are additional functions that let you narrow your search to a particular field: "bbdb-name", "bbdb-company", "bbdb-net" and "bbdb-notes", which respectively search the name, company, e-mail address, and notes fields.

To output records matching the regular expression "*\.edu" in the e-mail address, type:

M-x bbdb-net

Next week: using Linux for reminders.

Michael Stutz was one of the first reporters to cover Linux and the free software movement in the mainstream press.

Read more Living Linux columns.

Copyright © 2009 O'Reilly Media, Inc.