%slice Example with 3 CSV Tables
Various flavors of %slice with three CSV tables
The source tables
This example puts three tables together with %merge, and builds a newly-structured table from them using %slice.This one-week food plan table in English language is used as the root table:
Weekday | Date | Breakfast | Lunch | Dinner |
---|---|---|---|---|
Monday | 2024-12-16 | Muesli | Colorful garden salad | Noodle soup |
Tuesday | 2024-12-17 | Muesli | Sandwiches | Tomato soup |
Wednesday | 2024-12-18 | Muesli | Lamb's lettuce | Potato soup |
Thursday | 2024-12-19 | Bread rolls | Coleslaw | Chicken soup |
Friday | 2024-12-20 | 2 rolls | Tomato salad | Fish soup |
Furthermore, there is a similar plan in Spanish language:
Día laborable | Fecha | Desayuno | Almuerzo | Cena |
---|---|---|---|---|
martes | 2024-12-17 | Muesli | Sándwiches | Sopa de tomate |
miércoles | 2024-12-18 | Muesli | Canónigos | Sopa de patatas |
Jueves | 2024-12-19 | Bollos de pan | Ensalada de col | Sopa de pollo |
Lunes | 2024-12-16 | Muesli | Ensalada colorida de la huerta | Sopa de fideos |
Viernes | 2024-12-20 | 2 panecillos | Ensalada de tomate | Sopa de pescado |
And also in German language:
Wochentag | Datum | Frühstück | Mittagessen | Abendessen |
---|---|---|---|---|
Sonntag | 15.12.2024 | Kaffee | Pizza | Aalsupp |
Montag | 16.12.2024 | Müsli | Bunter Gartensalat | Nudelsuppe |
Dienstag | 17.12.2024 | Müsli | Sandwiches | Tomatensuppe |
Mittwoch | 18.12.2024 | Müsli | Feldsalat | Kartoffelsuppe |
Donnerstag | 19.12.2024 | Brötchen | Krautsalat | Hühnersuppe |
Freitag | 20.12.2024 | 2 Brötchen | Tomatensalat | Fischsuppe |
Merging the three tables using %merge
At first, we want to just straightly merge all tables into a single output table, with the respective date field as the reference field. The %merge command simply concatenates all fields of all tables, starting with the input table.
The English and the Spanish date format are identical, so the date field of the Spanish CSV table can be referred directly.
But regarding the German CSV table, the date format has to be changed from YYYY-MM-DD to DD.MM.YYYY. We use an intermediate helper variable for this, named
Furthermore, the redundant date fields (Spanish:
A %job file for processing all of this will look like this:
merge3.job
# the input file
meals-de.csv
# make the helper variable
+regex[[german-date]]=[Date]/(\d\d\d\d)-(\d\d)-(\d\d)/\3.\2.\1
# merge the Spanish table
%merge[Date]=[Fecha]@meals-es.csv.txt
+delete[Fecha]
# merge the German table
%merge[[german-date]]=[Datum]@meals-de.csv.txt
+delete[Datum]
# the output file
meals-merged.csv
And this processing will result in
Weekday | Date | Breakfast | Lunch | Dinner | Día laborable | Desayuno | Almuerzo | Cena | Wochentag | Frühstück | Mittagessen | Abendessen |
---|---|---|---|---|---|---|---|---|---|---|---|---|
Monday | 2024-12-16 | Muesli | Colorful garden salad | Noodle soup | Lunes | Muesli | Ensalada colorida de la huerta | Sopa de fideos | Montag | Müsli | Bunter Gartensalat | Nudelsuppe |
Tuesday | 2024-12-17 | Muesli | Sandwiches | Tomato soup | martes | Muesli | Sándwiches | Sopa de tomate | Dienstag | Müsli | Sandwiches | Tomatensuppe |
Wednesday | 2024-12-18 | Muesli | Lamb's lettuce | Potato soup | miércoles | Muesli | Canónigos | Sopa de patatas | Mittwoch | Müsli | Feldsalat | Kartoffelsuppe |
Thursday | 2024-12-19 | Bread rolls | Coleslaw | Chicken soup | Jueves | Bollos de pan | Ensalada de col | Sopa de pollo | Donnerstag | Brötchen | Krautsalat | Hühnersuppe |
Friday | 2024-12-20 | 2 rolls | Tomato salad | Fish soup | Viernes | 2 panecillos | Ensalada de tomate | Sopa de pescado | Freitag | 2 Brötchen | Tomatensalat | Fischsuppe |
blabla.