14 Generating Reports

Having a list of names and addresses, one might want to use this list to address envelopes (say, to send annual greeting cards). Since addresses are normally written on several lines, it would be appropriate then to split the Address field values across multiple lines as described in Fields. Suitable text can now be obtained thus:

$ recsel -t Person -j Abode -P Name,Abode_Address acquaintances.rec
Charles Spencer
2 Serpe Rise,
Little Worning,
SURREY

Dirk Spencer
2 Serpe Rise,
Little Worning,
SURREY

Ernest Wright
1 Wanter Rise,
Greater Inncombe,
BUCKS

A business enterprise might want to go one step further and generate letters (such as an advertisement or a recall notice) to customers. Since recsel merely selects records and fields from record sets, on its own it cannot do this; so there is another command designed for this purpose, called recfmt. This command uses a template which defines the general form of the desired output. A letter template might look as follows:

{{Name}}
{{Abode_Address}}

Dear {{Name}},

     Re: Special offer for January

We are delighted to be able to offer you a 95% discount on all car and
truck hire contracts between 1 January and 2 February.  Please call us
to take advantage of this offer.

Yours sincerely,


Karen van Rental (CEO) 
^L

It is best to place such a template into a file, so that you can edit it as you wish. Notice the instances of double braces enclosing a field name, e.g. {{Name}}. These are called slots and indicate places where the respective field’s value should be placed. Let’s assume this template is in a file called offer.templ. We can then pipe the output from recsel into recfmt in order as follows:

$ recsel -t Person -j Abode acquaintances.rec | recfmt -f offer.templ
Charles Spencer
2 Serpe Rise,
Little Worning,
SURREY

Dear Charles Spencer,

     Re: Special offer for January

We are delighted to be able to offer you a 95% discount on all car and
.
.
.

For each record that recsel selects, one copy of offer.templ will be generated. Each slot will be replaced with the field value corresponding to the field name in the slot.