17.2 Invoking recsel

recsel reads the given rec files (or the data in the standard input if no file is specified) and prints out records (or part of records) based upon some criteria specified by the user.

recsel searches rec files for records satisfying certain criteria. Synopsis:

recsel [option]... \
       [-n indexes | -e record_expr | -q str | -m num] \
       [-c | (-p|-P|-R) field_expr] \
       [file]...

If no file is specified then the command acts like a filter, getting the data from standard input and writing the result to standard output.

In addition to the common options described earlier (see Common Options) the program accepts the following options.

The following global options are available.

-i
--case-insensitive

Make string matching case-insensitive in selection expressions.

-C
--collapse

Do not section the result in records with newlines.

-d
--include-descriptors

Print record descriptors along with the matched records.

-s secret
--password=secret

Try to decrypt confidential fields with the given password.

-S
--sort=fields

Sort the output by the comma-separated list of field names, fields. This option takes precedence over any sorting criteria specified in the corresponding record descriptor with %sort.

-U
--uniq

Remove duplicated fields in the output records. Fields are duplicated if they have the same field name and the same value.

-G
--group-by=fields

Group the output records by the provided comma-separated list of fields. Grouping is performed before sorting.

The selection options are used to select a subset of the records in the input.

-n indexes
--number=indexes

Match the records occupying the given positions in its record set. indexes must be a comma-separated list of numbers or ranges, with ranges being two numbers separated with dashes. For example, the following list denotes the first, the third, the fourth and all records up to the tenth: ‘-n 0,2,4-9’.

-e expr
--expression=expr

A record selection expression (see Selection Expressions). Only the records matched by the expression will be taken into account to compute the output.

-q str
--quick=str

Select records having a field whose value contains the substring str.

-m num
--random=num

Select num random records. If num is zero then select all the records.

-t type
--type=type

Select records of a given type only.

-j field
--join=field

Perform an inner join of the record set selected by -t and the record set for which field is a foreign key. field must be a field declared with type rec and thus must be a foreign key. If a join is performed then any selection expression and field expression operate on the joined record sets.

The output options are used to determine what information about the selected records to display to the user, and how to display it.

-p name_list
--print=name_list

List of fields to print for each record. name_list is a list of field names separated by commas. For example:

-p Name,Email

means to print the Name and the Email of every matching record, both the field names and values.

If this option is not specified then all the fields of the matching records are printed to standard output.

-P name_list
--print-values=name_list

Same as ‘-p’, but print only the values of the selected fields.

-R name_list
--print-row=name_list

Same as ‘-P’, but print the values separated by single spaces instead of newlines.

-c
--count

If this option is specified then recsel will print the number of matching records instead of the records themselves. This option is incompatible with -p, -P and -R.

This special option is available to ease the communication between the recutils and other programs, namely Lisp interpreters. This option is not intended to be used by human operators.

--print-sexps

Print the data using sexps instead of rec format.