±columns
Rearrange CSV columns for output
Description
This command rearranges columns from reading (when input) or for output (when writing).
It defines which columns in which order shall be returned.
You can specify a comma-separated list of fields for output.
And you can specify column ranges denoted with a hyphen.
Pattern
±columns=[Field],[NextField],[OneMoreField] ... ±columns=[Field],[FieldFrom]-[FieldTo],...
Usage examples
This is the input file names.csv.City | FirstName | LastName | Birth | Driver License |
---|---|---|---|---|
Rome | Andrea | Bocelli | 1958 | y |
Los Angeles | Lieutnant | Columbo | 1927 | y |
London | Hercule | Poirot | 1910 | - |
New York | Theodoros | Kojak | 1922 | y |
- csvfox names.csv -columns=[City],[LastName],[Birth],[Driver License] nofirstnames.csv
-
This denotes all columns in the original order, but omits the column
FirstName . The resulting CSV table is written to nofirstnames.csv.nofirstnames.csv City LastName Birth Driver License Rome Bocelli 1958 y Los Angeles Columbo 1927 y London Poirot 1910 - New York Kojak 1922 y - csvfox names.csv -columns=[Driver License],[Birth],[LastName],[City] reverse_nofirstnames.csv
-
This reverses all columns order, and again omits the column
FirstName . The resulting CSV table is written to reverse_nofirstnames.csv.reverse_nofirstnames.csv Driver License Birth LastName City y 1958 Bocelli Rome y 1927 Columbo Los Angeles - 1910 Poirot London y 1922 Kojak New York - csvfox names.csv -columns=[City]-[LastName] city_names.csv
- This command defines a range of three columns (
City ,FirstName , andLastName ) and the filename city_names.csv for output.city_names.csv City FirstName LastName Rome Andrea Bocelli Los Angeles Lieutnant Columbo London Hercule Poirot New York Theodoros Kojak
Hint
This command is meant for rearranging column output completely, or for writing only a few of many columns.
If you just want to prevent output of one or two CSV columns, consider using (%[hide]%) instead.