±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:
The new columnfullnames.csv City 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 Last Name shall become separated from the current columnName by a whitespace. That whitespace is lost.
After this, the columnName was renamed toFirst Name for correctness.The resulting CSV table is written to firstlastnames.csv.firstlastnames.csv 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 - -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.City Left Part Right Part Birth Driver License Rome Andrea Bo celli 1958 y Los Angeles Lieutnant Co lumbo 1927 y London Hercule Po irot 1910 - New York Theo doros Kojak 1922 y - -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.City Left Part Right Part Birth Driver License Rome Andrea B ocelli 1958 y Los Angeles Lieutnant C olumbo 1927 y London Hercule P oirot 1910 - New York The odoros Kojak 1922 y - -split/n[Name]@["Right Part"]=5 +rename[Name]=["Left Part"]
- The new column is separated from the existing column
Name after the fifth character.City Left Part Right Part Birth Driver License Rome Andre a Bocelli 1958 y Los Angeles Lieut nant Columbo 1927 y London Hercu le Poirot 1910 - New York Theod oros Kojak 1922 y - -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 .City Left Part Right Part Birth Driver License Rome Andrea Bo celli 1958 y Los Angeles Lieutnant Co lumbo 1927 y London Hercule P oirot 1910 - New York Theodoros Kojak 1922 y