CSVfox
Leverage Your Data.
 English

%merge

Merges all fields from an additional CSV file to the current row.

Description

This command merges additional columns from another CSV file to the current row of the input file.

For each line of the input file, it uses a local and a remote key field, comparing both fields to find the correct data (CSV row) in the additional file. Then it appends that row's fields to the local data fields.

All "+"commands before the %merge command refer to the input file, while all "+"commands afterwards refer to the additionally merged file.
All "-" column or field commands will then refer to the combined input and merged fields in the output file. At last, all fields will then be written togther into the output file (as long as they are not hidden, see also ±hide and ±columns). 

Pattern

%merge=filename %merge[localfield]=filename %merge[localfield]=[remotefield]@filename

If all field names are omitted, the command will use the first column of the input file as the local key, and, if exists, a column with the same name in the additional file as the remote key.
If there is no column with an identical column name, the first column in the additional file will be compared with the first column of the input file.

If only the local key field is defined, the command will use a column of the additional file with the same name as this column. If  such column does not exist, the first column of the additional file will be used as remote key.

If only the remote key is given, it will be compared to the first column of the input file.
 

Usage examples

Say we have a table of articles:
articles.csv
IDDescriptionPriceVATfoo
12Bread0.751bla
15Milk1.501blub
18Trousers49.992bar
23Golden Watch2000.003what
55Pair of Shoes99.902brand

And there is another table about VAT rates:
vat-rates.csv
IDNameRate
0VAT free0
1Reduced VAT7
2Normal VAT19
3Luxus VAT25

As we can see, the column VAT in table articles.csv matches with the column ID in table vat-rates.csv .

Using this, we can merge the respective VAT rates into the articles table:
articles.csv %merge[VAT]=[ID]@vat-rates.csv articles-with-vat.csv
This will be the resulting table:
articles-with-vat.csv
IDDescriptionPriceVATfooIDNameRate
12Bread0.751bla1Reduced VAT7
15Milk1.501blub1Reduced VAT7
18Trousers49.992bar2Normal VAT19
23Golden Watch2000.003what3Luxus VAT25
55Pair of Shoes99.902brand2Normal VAT19

Optionally:
Having done this, one can also calculate the gross price in an additional column.
At last, the columns can be rearranged for a more concise article file, if desired.
articles.csv %merge[VAT]=[ID]@vat-rates.csv -add[GrossPrice]="{([Price]+[VAT]%).2}" -columns=ID,Description,Price,Rate,GrossPrice articles-with-vat.csv
This will be the resulting table:
articles-with-vat.csv
IDDescriptionPriceRateGrossPrice
12Bread0.7570.80
15Milk1.5071.60
18Trousers49.991959,49
23Golden Watch2000.00252500.00
55Pair of Shoes99.9019118,88
Under construction, coming soon