Index is used to maintain simple databases such as address lists, lists of books or compact discs, and so on. All databases are stored as simple text files in a single directory. By default, this directory resides in your home directory, and is called .index. You can specify a different path name for the directory by setting the environment variable INDEXDIR to the directory's full path name.
When invoked with no arguments, index will present you with a list of the databases you have, and ask you to select the one you want to work with. To create a new database, simply type the name of a non-existent database to the prompt. The name of an existing database may also be specified on the command line, bypassing this step and going directly to the main menu.
When you specify the name of a non-existent database to the database selection prompt, you will be placed in a text editor to create the database description file. This file is simply a list of the field names for the database, one per line. You may have up to 16 fields in each database. Blank lines may be used for continuation lines in multiple-line fields, such as addresses.
The database is always sorted by the first field. When searching the database, the default is to search all fields for the pattern. To specify that a field should be ignored in searching, you should place an exclamation point (!) in the first position on that line.
When you have created the database description file, save the file and exit the editor. You will then be placed in the main menu, where you can manipulate the database.
The main menu is the point from which the database can be manipulated. This menu provides you with several commands:
If a database name and pattern are both specified on the command line, the pattern will be searched for in the database, and any matching entries will be printed on the standard output. Each entry will be printed one field per line, preceded by its field name.
The pattern may be any valid regular expression, as defined by ed(1). Case is significant, unless the -i option is given. To match all entries in the database, use the regular expression ``.'' (matches any character).
By default, index will not print any blank lines in the entry, in order to make the output more readable. By specifying the -v option, you can tell index to print all lines in the entry, even if they have nothing on them.
If the -f option is specified with the name of a filter, then when a database name and pattern are also given, all matching entries will be sent through the filter program instead of to the standard output.
The first line of output will contain the field names for the database, separated by tabs. Each following line will contain one database entry, with fields separated by tabs. This format is easily dealt with using programs such as awk(1).
As a convenience, filtering programs may be stored in the database directory with a ``.fmt'' extension in their file name. The program is first searched for here (by adding the name extension), and if it is not found, it is then searched for (without the extension) in the standard search path.
The following database description file implements a business phone number list. It allows three lines for the company address, and two lines for electronic mail addresses. The extra fields ``Product'' and ``Keywords'' can be used to provide additional patterns to search for (e.g., you might want to search for all disk vendors). The ``!'' character inhibits searching the title, address, and telephone number for patterns.
Name !Title Company !Address ! ! !Phone Electronic Mail Product Keywords
Each database may have no more than 16 fields.
You may not have more than 64 separate databases.
A database may contain as many entries as you can allocate memory for.