CSVfox
Leverage Your Data.
 English

%slice/single

Split all data columns of a CSV data row into separate rows

Slice single test

Usage

This function can be used to wrap data fields from a single CSV row into multiple separate rows for output. 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[startfield] %slice[startfield]=[titlecolumn_name],[valuecolumn_name]
%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 column Field 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 column Field 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 titles COLUMN_TITLE and COLUMN_VALUE are created during output.
If 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: +rename[COLUMN_TITLE]="My New Title" +rename[COLUMN_VALUE]="My New Value" to match the meaning of the output file columns.

Example

This is a tabular weekly schedule as csv:

WeekdayBreakfastLunchDinner
MondayMuesliColorful garden saladNoodle soup
TuesdayMuesliSandwichesTomato soup
WednesdayMuesliLamb's lettucePotato soup
ThursdayBread rollsColeslawChicken soup
Friday2 rollsTomato saladFish soup
and after applying
%slice
this will result in
WeekdayCOLUMN_TITLECOLUMN_VALUE
MondayBreakfastMuesli
MondayLunchColorful garden salad
MondayDinnerNoodle soup
TuesdayBreakfastMuesli
TuesdayLunchSandwiches
TuesdayDinnerTomato soup
WednesdayBreakfastMuesli
WednesdayLunchLamb's lettuce
WednesdayDinnerPotato soup
ThursdayBreakfastBread roll
ThursdayLunchcoleslaw
ThursdayDinnerChicken soup
FridayBreakfast2 rolls
FridayLunchtomato salad
FridayDinnerfish soup
Here, for the sake of completeness and better readibility, one should also rename the titles.
By using the following commands: +rename[COLUMN_TITLE]=Daytime +rename[COLUMN_VALUE]=Meal meaningful column headings will be added.

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/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 value
 with two mergefiles: must specify a start fixed offset in each merged file: @slice/distinct[Offset]=[3],[3]
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])
 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.
 
Under construction, coming soon