As was explained in the previous sections, recsel outputs all the records of some record set. The records are echoed in the same order they are written in the recfile. However, often it is desirable to select a subset of the records determined by the position they occupy in their record set.
-n command line argument to recsel allows to do
this in a very easy way. This is how we would retrieve the first
contact listed in a contacts database using recsel:
$ recsel -n 0 contacts.rec Name: Granny Phone: +12 23456677
Note that the index is 0-based. In case we want to retrieve more
records we can specify several indexes to
-n separated by
commas. In case an index is too big then it is simply ignored:
$ recsel -n 0,1,999 contacts.rec Name: Granny Phone: +12 23456677 Name: Doctor Phone: +12 58999222
Note that the order in which the records are echoed does not
depend on the order of the indexes passed to
This means that the output of recsel -n 0,1 will be
identical to the output of recsel -n 1,0.
Ranges of indexes can also be used to select a subset of the records. For example, the following call would also select the first three contacts of the database:
$ recsel -n 0-2 contacts.rec Name: Granny Phone: +12 23456677 Name: Doctor Phone: +12 58999222 Name: Dad Phone: +12 88229900
Note that it is possible to mix concrete indexes and index ranges in the same call. For example, recsel -n 0,5-6 would select the first, the fourth and the fifth records in some record descriptor.