select(1)

NAME
select - extract fields from simple text databases

SYNOPSIS
select [-M|-S schemafile |-N] [-m] [-f fieldseps] [-o] [-i] [-c] fieldname ... -from filename ... -where conditional ...

DESCRIPTION

This is similar in concept to a SQL SELECT statement, which explains the somewhat weird syntax. It operates on simple text database files - each record is one line in the file, and data items are separated by the designated field separator character, generally tab.

The command extracts the specified fields from the specified files, but only those records which match the specified conditionals. At least one fieldname and one filename must be specified. If you don't specify any conditionals then you get every record. If you specify "-all" as the fieldname then you get all fields in each selected record.

This is certainly much slower than a real database; however it's faster and much easier than doing ad-hoc textfile parsing using shell scripts and sed/awk. If your database is reasonably small, say up to a few thousand records, and you need command-line access to it, this program should be useful.

OPTIONS

-M/-S/-N
    These flags specify which input format you want to use. You must specify one of the three, there is no default. See the INPUT FORMATS section below for what the options mean.

-m  This says to treat multiple field separators as one. The default is for each individual field separator character to actually separate a field. If you specify the -m flag, then two or three or any number of adjacent field separators are treated as a single field separator. The advantage is you can make your database columns line up and look nice. The disadvantage is, you can't have any empty fields.

-f  Lets you specify alternate field separators. The default is tab. If you specify more than one character, they all become field separators.

-o  This flag specifies "or" mode - print rows for which any of the conditionals match, instead of the usual way which requires they all match.

-i  This flag tells select to ignore upper/lower case when doing string or wildcard matching.

-c  This flag tells select to generate column names in the output, so that it is a valid input file for further select calls. Without -c, the output is just the data items. With it, you get a header line with the column names for -M/-S inputs, or "colname=data" for -N inputs.

CONDITIONALS

The conditionals are of the form "fieldname op str". Available operators:

=   String or wildcard or numeric equality.

!=  String or wildcard or numeric non-equality.

<   Numeric less-than.

<=  Numeric less-than or equals.

>   Numeric greater-than.

>=  Numeric greater-than or equals.

The wildcard patterns for the "=" and "!=" operators are Unix-style, not SQL style. I.e. "^.*[xyz]$" etc.

Conditionals on fieldnames which don't appear in the input line are evaluated as if the input was an empty string. Numeric comparisons on non-numeric input are evaluated as if the input was zero.

INPUT FORMATS

There are three possible input formats, two of which are very similar to each other. All three have some things in common:

    Anything after a '#' is considered a comment and is ignored.

    Blank lines are ignored.

    Records may be continued across multiple plysical lines by beginning the second and subsequent lines with a separator.

Aside from that, the three formats work as follows:

Merge
    This is specified by the -M flag. The first line of each file is a database schema, consisting of a list of field names. Subsequent lines have values in the corresponding positions.

Schema
    This is specified by the -S flag, which is accompanied by a filename. The format is the same as the Merge format except that the schema, instead of appearing on the first line of each file, comes from the separate schema file.

Name-Value
    This is specified by the -N flag. All data is specified as "name=value" pairs.

AUTHOR
Copyright © 2000 by Jef Poskanzer <jef@mail.acme.com>. All rights reserved.