CSVfox
Leverage Your Data.
 English

±split

Split a CSV column into two columns, using a separator or a position

Description

Splits a column into two columns by inserting a new one after the current (named) column. The content is split between the current and the new column.

There are four modes of splitting:

  • split at the separator. The separator itself will be lost.
  • split/l (split left). The separator will be appended to the left (existing) column.
  • split/r (split right). The separator will be prepended to the right (new) column.
  • split/n (split at position). Split after the n'th character of the existing column.

Pattern

±split[CurrentColumn]@[NewColumn] ±split[CurrentColumn]@[NewColumn]=separator ±split/mode[CurrentColumn]@[NewColumn]=separator


The separator string (separator) is defined by the parameter. The character string behind the separator will be transferred to the new column.
If no separator is given, then the '/' is assumed.
If the separator is not found in the column contents, the new column remains empty.
The separator can be an expression, which is resolved. Examples:

Usage examples:

csvfox fullnames.csv -split[Name]@["Last Name"]=" " +rename[Name]=["First Name"] firstlastnames.csv
This CSV table will be used in the following examples:
fullnames.csv
CityNameBirthDriver License
RomeAndrea Bocelli1958y
Los AngelesLieutnant Columbo1927y
LondonHercule Poirot1910-
New YorkTheodoros Kojak1922y
The new column Last Name shall become separated from the current column Name by a whitespace. That whitespace is lost.
After this, the column Name was renamed to First Name for correctness.The resulting CSV table is written to firstlastnames.csv.
firstlastnames.csv
CityFirst NameLast NameBirthDriver License
RomeAndreaBocelli1958y
Los AngelesLieutnantColumbo1927y
LondonHerculePoirot1910-
New YorkTheodorosKojak1922y
-split/l[Name]@["Right Part"]="o" +rename[Name]=["Left Part"]
The new column is separated from the existing column Name at the first occurrence of the character "o". The "o" is appended to the current (left) column.
CityLeft PartRight PartBirthDriver License
RomeAndrea Bocelli1958y
Los AngelesLieutnant Columbo1927y
LondonHercule Poirot1910-
New YorkTheodoros Kojak1922y
-split/r[Name]@["Right Part"]="o" +rename[Name]=["Left Part"]
The new column is separated from the existing column Name at the first occurrence of the character "o". The "o" is prepended to the new (right) column.
CityLeft PartRight PartBirthDriver License
RomeAndrea Bocelli1958y
Los AngelesLieutnant Columbo1927y
LondonHercule Poirot1910-
New YorkTheodoros Kojak1922y
-split/n[Name]@["Right Part"]=5 +rename[Name]=["Left Part"]
The new column is separated from the existing column Name after the fifth character.
CityLeft PartRight PartBirthDriver License
RomeAndrea Bocelli1958y
Los AngelesLieutnant Columbo1927y
LondonHercule Poirot1910-
New YorkTheodoros Kojak1922y
-split/n[Name]@["Right Part"]=-5 +rename[Name]=["Left Part"]
A negative number means counting the position from the right end: The new column will consist of the last five characters of the existing column Name.
CityLeft PartRight PartBirthDriver License
RomeAndrea Bocelli1958y
Los AngelesLieutnant Columbo1927y
LondonHercule Poirot1910-
New YorkTheodoros Kojak1922y

Hint

You cannot swap or change the column destinations at this point in a way that the new column with the last part of the contents will be on the left side to the existing one. Instead, you will control the output visibility and order of the columns with the ±columns command. There you can specify any desired order of the columns.
Under construction, coming soon