%slice
Split data fields of a CSV data row to separate rows
Usage
This function can be used to wrap data fields from a single CSV row into multiple separate rows for output.Depending on the slice mode, the newly-built rows are made in different ways.
However, this command gets his full power together with the merge command. Data from various files can be formed to useful data rows, according to the user's needs.
Slice/Single: The first field or fields remain the same in each generated row, followed by two new fields: the respective column heading and the contents.
This command can only be used for output control, not for reading a CSV file.
- %slice
- Starting with the second column, all subsequent fields are split into separate rows.
Each output row consists of three fields:
Field[1], the respective column name in a separate column, and the respective field content in a separate column. - %slice[4]
- Starting with the fourth column (
4 ), the subsequent fields are divided into individual lines.
Each output line consists of the preceding fields [1]-[3], the column name in a separate column, and the field contents in a separate column. - %slice["Field Name"]
- Starting with the column
Field Name the subsequent fields are divided into individual lines.
Each output row consists of all fields preceding the columnField Name , the column name in a separate column, and the field contents in a separate column. - %slice["Field Name"]=[NewColumnTitle],[NewValueTitle]
- Starting with the column
Field Name the subsequent fields are divided into individual lines.
Each output row consists of all fields preceding the columnField Name , the column name in a separate column named [NewColumnTitle], and the field contents in a separate column named [NewValueTitle].
Special feature
As the new table will have some additonal columns for each "sliced" value, a number of new generic column titlesIf the command %merge is used, there will even be new columns für each column of every merged file. See also %merge .
These columns should be renamed as desired.
Do this by using, for example:
Example
This is a tabular weekly schedule as csv:
Weekday | Breakfast | Lunch | Dinner |
---|---|---|---|
Monday | Muesli | Colorful garden salad | Noodle soup |
Tuesday | Muesli | Sandwiches | Tomato soup |
Wednesday | Muesli | Lamb's lettuce | Potato soup |
Thursday | Bread rolls | Coleslaw | Chicken soup |
Friday | 2 rolls | Tomato salad | Fish soup |
- %slice
Weekday | COLUMN_TITLE | COLUMN_VALUE |
---|---|---|
Monday | Breakfast | Muesli |
Monday | Lunch | Colorful garden salad |
Monday | Dinner | Noodle soup |
Tuesday | Breakfast | Muesli |
Tuesday | Lunch | Sandwiches |
Tuesday | Dinner | Tomato soup |
Wednesday | Breakfast | Muesli |
Wednesday | Lunch | Lamb's lettuce |
Wednesday | Dinner | Potato soup |
Thursday | Breakfast | Bread roll |
Thursday | Lunch | coleslaw |
Thursday | Dinner | Chicken soup |
Friday | Breakfast | 2 rolls |
Friday | Lunch | tomato salad |
Friday | Dinner | fish soup |
By using the following commands:
Special modes
There are some specialties when using %slice together with %merge.
In this case, for each merged file there will be added one column[field name] (field value, %slicecompact) or even two columns (field name and value, %slicedistinct) to each data row.
=> Eigene Seiten mit Beispielen!
%slice/single[Offset]: splits each subsequent columns, starting with [offset], into own rows. Common first fields before [Offset], followed by two new fields: the respective column name and the field contents.
with %merge: for each mergefile, all columns are handled accordingly.
%slice/distinct[Offset] starting past [Offset] splits all columns into own rows (%slice is the same as %slice[1] is the same as %slicedistinct[1])
with %merge: for each mergefile, starting from offset, for each mergefile add two columns, with field name and field valuewith two mergefiles: must specify a start fixed offset in each merged file:
This is made for adding arbitrary columns from the merged file(s).
%slice/compact[field name] starting past [field name] splits all columns into own rows
(when used without %merge, this is identical to %slice[Field name] resp. %slice/distinct[Field name])
This works only when all columns have column header names, and when the merge files contain(s) the same column names!
Application example: attributes in several languages
with %merge: for each merged file, add one column [field name] with the field value of [field name]
with two mergefiles: no fixed offsets necessary, because offset of [field name] is picked out each time
This is made for combining columns from the merged file(s) with the same name.