Next: , Up: Querying Recfiles   [Contents][Index]


3.1 Simple Selections

recsel is an utility whose primary purpose is to select records from a recfile and print them on standard output. Consider the following example record set, which we shall assume is saved in a recfile called acquaintances.rec:

# This database contains a list of both real and fictional people
# along with their age.

Name: Ada Lovelace
Age: 36

Name: Peter the Great
Age: 53

# Name: Matusalem
# Age: 969

Name: Bart Simpson
Age: 10

Name: Adrian Mole
Age: 13.75

If we invoke recsel acquaintances.rec we will get a list of all the records stored in the file in the terminal:

$ recsel acquaintances.rec
Name: Ada Lovelace
Age: 36

Name: Peter the Great
Age: 53

Name: Bart Simpson
Age: 10

Name: Adrian Mole
Age: 13.75

Note that the commented out parts of the file, in this case the explanatory header and the record corresponding to Matusalem, are not part of the output produced by recsel. This is because recsel is concerned only with the data.

recsel will also “pack” the records so any extra empty lines that may be between records are not echoed in the output:

acquaintances.rec:

Name: Peter the Great
Age: 53

# Note the extra empty lines.


Name: Bart Simpson
Age: 10
$ recsel acquaintances.rec
Name: Peter the Great
Age: 53

Name: Bart Simpson
Age: 10

It is common to store data gathered in several recfiles. For example, we could have a contacts.rec file containing general contact records, and also a work-contacts.rec file containing business contacts:

contacts.rec:

Name: Granny
Phone: +12 23456677

Name: Doctor
Phone: +12 58999222
work-contacts.rec:

Name: Yoyodyne Corp.
Email: sales@yoyod.com
Phone: +98 43434433

Name: Robert Harris
Email: robert.harris@yoyod.com
Note: Sales Department.

Both files can be passed to recsel in the command line. In that case recsel will simply process them and output their records in the same order they were specified:

$ recsel contacts.rec work-contacts.rec
Name: Granny
Phone: +12 23456677

Name: Doctor
Phone: +12 58999222

Name: Yoyodyne Corp.
Email: sales@yoyod.com
Phone: +98 43434433

Name: Robert Harris
Email: robert.harris@yoyod.com
Note: Sales Department.

As mentioned above, the output follows the ordering on the command line, so recsel work-contacts.rec contacts.rec would output the records of work-contacts.rec first and then the ones from contacts.rec.

Note however that recsel will merge records from several files specified in the command line only if they are anonyomuse. If the contacts in our files were typed:

contacts.rec:

%rec: Contact

Name: Granny
Phone: +12 23456677

Name: Doctor
Phone: +12 58999222
work-contacts.rec:

%rec: Contact

Name: Yoyodyne Corp.
Email: sales@yoyod.com
Phone: +98 43434433

Name: Robert Harris
Email: robert.harris@yoyod.com
Note: Sales Department.

Then we would get the following error message:

$ recsel contacts.rec work-contacts.rec
recsel: error: duplicated record set 'Contact' from work-contacts.rec.

Next: , Up: Querying Recfiles   [Contents][Index]