map

Commands ››
Parent Previous Next

The map command allows you to map CSV field values from one value to another. You can do the same thing with the edit command, but map is generally easier to use for simple cases, as it does not require expertise in regular expressions.

See also: edit

Flag

Req'd?

Description

-f fields

No

Specified a comma-separated list of fields to perform mapping on. If not specified, all fields are used. You can specify fields using the range syntax.

-fv values

Yes

Specifies a comma-separated list of values to map from. The items in the list are treated as literal values, not regular expressions.

-tv values

Yes

Specifies a list of values to map to. This list may be empty but cannot contain more values than the from list. When mapping is performed, values in the from list are mapped to values at the same position in the to list. If there is no matching value, the last value in in the to list is used. You can thus map multiple values in a from list to a single value in a to list.


The special values $1, $2 .. $N are treated as the values of fields 1,2 .. N  in the current CSV input  record. If you want to have a literal $ sign as the first value in a field, use $$.

-ic

No

Specifies if case should be ignored when testing if a mapping should be performed. The default is to respect case.



The following example changes the country code of those countries in the countries.csv file which are in the Euro zone to 'EUR':

csvfix map -f 1 -fv 'FR,NL,IT,DE' -tv 'EUR' data/countries.csv

which produces:

"GB","United Kingdom"
"EUR","France"
"EUR","Germany"
"EUR","Netherlands"
"EUR","Italy"
"US","United States"



Created with the Personal Edition of HelpNDoc: Easy CHM and documentation editor