±combine
Combines a new single CSV column out of two or more other columns
This command builds a new column from concatenating two or more existing columns, optionally replacing them at the same place.
The basic principle is simple:
Modes of Combining Columns
There are three modes of combining. The combining mode is defined by the command mode.
combine , orcombine/s . The denoted columns will be combined into one new column as described. The new column will be in the place of the leftmost of the existing columns. These columns will be lost.combine/l The new column will be inserted left to the leftmost of the existing columns. These columns will be kept also.combine/r The new column will be inserted right to the rightmost of the existing columns. These columns will be kept also.
The separator
The separator string is defined by an optional command parameter after the "=". The separator string, if one is given, will be inserted between each of the new columns.If there is no separator string given, the columns will be concatenated directly, without any separator.
Combining a new column from two other columns
This is most simple. Just name the existing columns, the new column name, and the desired separator that will be inserted, and the denoted columns will be replaced by the new one, if desired, or the existing columns will also be kept.Pattern
Usage examples:
This small CSV table will be used in the following examples:City | First_Name | Last_Name | Birth | Driver License |
---|---|---|---|---|
Rome | Andrea | Bocelli | 1958 | y |
Los Angeles | Lieutnant | Columbo | 1927 | y |
London | Hercule | Poirot | 1910 | - |
New York | Theodoros | Kojak | 1922 | y |
We will use the columns
- csvfox firstlastnames.csv -combine[Full_Name]@[First_Name],[Last_Name] fullnames.csv
First_Name andLast_Name shall be combined into the new field "Full_Name ".
The resulting CSV table is written to fullnames.csv.
Oops, we forgot the separator string!fullnames.csv City Full_Name Birth Driver License Rome AndreaBocelli 1958 y Los Angeles LieutnantColumbo 1927 y London HerculePoirot 1910 - New York TheodorosKojak 1922 y - -combine[Full_Name]@[First_Name],[Last_Name]=\s
- The same as above, but this time a whitespace shall be inserted as a separator.
City Full_Name Birth Driver License Rome Andrea Bocelli 1958 y Los Angeles Lieutnant Columbo 1927 y London Hercule Poirot 1910 - New York Theodoros Kojak 1922 y - -combine/l[Full_Name]@[First_Name],[Last_Name]=\s
- The same as above, but we insert the new column left to the existing columns, because we want to keep those also.
City Full_Name First_Name Last_Name Birth Driver License Rome Andrea Bocelli Andrea Bocelli 1958 y Los Angeles Lieutnant Columbo Lieutnant Columbo 1927 y London Hercule Poirot Hercule Poirot 1910 - New York Theodoros Kojak Theodoros Kojak 1922 y
- -combine/r[Full_Name]@[First_Name],[Last_Name]=\s
- The same as above, but this time we want to insert the new column right to the existing columns.
City First_Name Last_Name Full_Name Birth Driver License Rome Andrea Bocelli Andrea Bocelli 1958 y Los Angeles Lieutnant Columbo Lieutnant Columbo 1927 y London Hercule Poirot Hercule Poirot 1910 - New York Theodoros Kojak Theodoros Kojak 1922 y
Combining a column from more than two other columns
Description
This works exactly like before. You just denote even more new columns!
But because here more splitting takes place, there is the option to handle each splitting occurance differently (see below).
Pattern
Usage Examples:
To be completed ...
Name | ProductID | Gender | Level2 | Level3 | Level4 | Level5 | Price |
---|---|---|---|---|---|---|---|
Green Fashion Jacket | JACKET1 | Women | Outdoor | Jackets | Transitional | 220 $ | |
Black Rain Coat | RAINCOAT1 | Women | Outdoor | Coats | Rain | 200 $ | |
Rubber Flubber Rainboots | W4589356 | Women | Shoes | Boots | 100 $ | ||
Dragon Style Men's Blue Jeans | J4534656 | Men | Trousers | Jeans | Stonewashed | Used | 100 $ |
Using more separators for more fields
You can optionally define a series of splitting separator strings, one for each new column. In this case, the number of splitting separator strings must exactly correspond to the number of new columns minus 1, as each one will be used for separating one new field. These splitting separator strings must be concatenated by comma
If the comma iself must be specified as separator, and it is the only separator, just write
But if the comma is part of a separator string instead, or included in the separator list, it must be escaped for clarity: