48.11 The index Database ProgramThe index program is a flexible database management program. index is pretty neat: it works by keeping two files for each database, a field description file and a file of sorted data. It's also fairly intuitive to use, once you get started. To use index, you should first set up a database directory. By default, index looks for the directory $HOME/.index .
Select a database: If you specify the name of a database that doesn't exist yet, index assumes that you want to create it. index puts you in the editor specified in your EDITOR ( 6.3 ) environment variable so you can list the titles for each field in the new database. Up to 16 fields can be supported. For example, you can create a database called addresses , defined to have the following fields:
NAME TITLE ORGANIZATION STREET ADDRESS CITY STATE ZIP CODE VOICE PHONE NUMBER FAX PHONE NUMBER EMAIL ADDRESS After exiting the editor, you are put into the main menu:
Database: addresses (0 entries) a - Add new entry to database f - Find entry in database r - Read database entry by entry s - Save modifications, do not exit q - Save modifications, exit x - Exit Command:
There are no entries in the new database. You can start adding entries
now by pressing When editing an entry in the database, you're prompted by each of the fields that were set up when the database was defined. After completing a field, press RETURN to get to the next field. There are also a limited number of escape sequences supported for editing and moving around - for example, CTRL-d to delete to the end of the line, or CTRL-p to move up a line. When you're done with the entire entry, press ESCAPE.
NAME: Once you've saved the new entry, you'll be back to the main menu. You can now add more entries, look at existing entries, search for a string in one of the existing entries, or exit.
To search for an existing entry, press
Pattern to search for: The index program searches all fields matching the string. Regular expressions ( 26.4 ) are also accepted in the search string. Each entry with the matching string is shown, one-by-one:
NAME: Benjamin Braddock TITLE: Sales Manager ORGANIZATION: Acme Plastics, Inc. STREET ADDRESS: 103 Morris St., Suite A CITY: Tucson STATE: AZ ZIP CODE: 85472 VOICE PHONE NUMBER: 800-998-9938 FAX PHONE NUMBER: 800-999-9999 EMAIL ADDRESS: ben@acme.com <RET> = next entry "d" = delete this entry "-" = previous entry "e" = edit this entry "q" = return to main menu Command: You can also search for strings on the index command line. To do so, specify both the database name and the string. (Enclose the search string in single quotes ( 8.14 ) if you want to use a regular expression.)
% All matching entries will be printed to standard output. The most common use for a database like this is to maintain information about people. But you can use index to maintain all sorts of information. For example, you might keep one for information about local restaurants:
NAME: Rooster BBQ & Grill STREET ADDRESS: 1122 Rooster Ave. CITY: Cambridge PHONE: 555-1212 RESERVATIONS (y,n): n FOOD (1=poor, 10=excellent): 8 DECOR (1=poor, 10=excellent): 2 SERVICE (1=poor, 10=excellent): 6 RECOMMENDED DISHES: Baby-back ribs, Elvis pizza STAY AWAY FROM: Pulled turkey plate, mango pie RECOMMENDED BY: Jerry, Boston Phoenix For even more flexibility, index can run a filter program ( 48.12 ) . - |
|