row

Usage: row [options] expression

Options:

Selects rows from the input rdbtable based on an arbitrary expression using column names. Characters that are special to the UNIX shell must be quoted.

Logical constructors 'or' and 'and' may be used; as well as 'null' to indicate empty data values. Comparison operators may be of the form: gt, ge, lt, le, eq, ne, mat, nmat. The first six are the usual operators, E.g 'name eq Hobbs' or 'COUNT gt 100'. The last two stand for 'match' and 'non-match' and are used for pattern matching. They are exactally the same as using the PERL operators '=~' or '!~' respectively, except that pattern matching can be specified easier in expressions, as in:

        NAME  mat   /[Hh]obbs/ 		<<< First letter either case
        NAME  mat   /hobbs/i		<<< any combination of case
        NAME  nmat  /[aeiou]/i		<<< names without vowels
where 'NAME' and 'COUNT' are column names, of course. A warning message is produced on STDERR if either of 'mat' or 'nmat' is used with a numeric type column, but the execution continues. It does not check the '=~' or '!~' forms.

All of the Comparison operators and Logical constructors are reserved and should not be used as column names (they are all lower case and four characters or less).

Since column names and reserved words are parsed by the program, do not put the entire expression in a single pair of quotes as that will prevent the parsing. Also note that column names and reserved words need to be surrounded by blank spaces if they are not individually quoted. For example either form below is fine:

        row   NAME    eq   "L Brown"  <  sample
        row  "NAME"  "eq"  "L Brown"  <  sample
but do not use this form:
        row  "NAME  eq  L Brown"  <  sample

This operator reads an rdbtable via STDIN and writes an rdbtable via STDOUT. Options may be abbreviated.

As an example using the sample rdbtable from the DATA section (named sample), to select rows that have the NAME column equal to 'Hansen' the command would be:

        row  NAME  eq  Hansen  <  sample
which would produce:
        NAME    COUNT   TYP     AMT     OTHER   RIGHT
        6       5N      4       5N      8       8>
        Hansen  44      A       23      One     Is
to select rows that have the TYP column equal to 'A' or that have the AMT column greater than 1000 the command would be:
        row  TYP  eq  A  or  AMT  gt  1000  <  sample
producing:
        NAME    COUNT   TYP     AMT     OTHER   RIGHT
        6       5N      4       5N      8       8>
        Bush    44      A       133     Another This
        Hansen  44      A       23      One     Is
        Hart    77      D       1111    So      Right
        Holmes  65      D       1111    On      Edge

Note that in some rare cases there could be a column name that is identical to a data value specified in an expression using another column name that might cause a problem (this actually happened). For example if two column names are 'N' and 'T', and column 'N' has a data value of 'T', to select all rows where column 'N' is equal to 'T' the normal command would be:

    row  <  table  N  eq  T
Unfortunately the 'T' in the expression gets translated to 'column name T', not used as 'data value T'. That is, the expression askes for all rows where the data value of column N equals the data value of column T, legal, but not what was wanted. There is a simple workaround however. The 'T' in the expression can be escaped with a backslash to prevent the translation to a column name, as in the revised command:
    row  <  table  N  eq  '\T'
Thus either meaning can be specified, as desired.