Next: , Previous: rec2csv Invocation, Up: rec2csv

27.2 rec2csv Conversion

Record sets are not tables, even if tables can be easily emulated using records having the same fields in the same order. For example:

     a: value
     b: value
     c: value
     a: value
     b: value
     c: value

There are several ways records are more flexible than tables:

Since comma-separated-values files contain tables, the rec2csv utility implements an algorithm that deals with the previous difficulties, to generate a table that is what the user expects (likewise).

The algorithm is the following. The utility first scans the specified record set, building a list with the names that will become the table header. For each field, a header is added with the form:


where N is a number in the range 2..inf and is the “index” of the field in its containing record plus one. For example, consider the following record set:

     a: a1
     b: b11
     b: b12
     c: c1
     a: a2
     b: b2
     d: d2

The corresponding list of headers being:

     a b b_2 c a b d

Then duplicates are removed:

     a b b_2 c d

The resulting list of headers is then used to build the table in the generated csv file. In this case:


Note how missing fields are implemented as empty rows in the generated csv.