flatten

Commands ››
Parent Previous Next

The flatten command is used to flatten multiple input rows into a single input row, depending on an identical key field or fields. This is useful if you have data like average temperature data for each month in a year (not all values shown):

1990, 0
1990, 0
1990, 4
...
1990, 2
1990, 1
1991, 1
...

and you would like them to look like:

1990, 0, 0, 4, ... 2, 1
1991, 1, ...

Values are pulled together so long as the key (in this case the year) for successive input rows is the same, and the flattened row is output when the key changes.

See also: unflatten


Flag

Req'd?

Description

-k key

No

Specifies one or more key fields. Default is to use the first field as the key

-f data

No

Specifies the data fields. By default, all fields except the key are considered to be data.

-r

No

Remove the key from the output. By default the key is retained and becomes the first field(s) in the output.



The following example flattens the data in the flat.csv file:

csvfix flatten data/flat.csv

producing:

"A","a1","a2","a3","a4"
"B","b1","b2"
"A","a5","a6"
"C","c1","c2","c3","c4"

Created with the Personal Edition of HelpNDoc: Full featured Documentation generator