Command line tool to map column names and field values of a CSV file.
With Go installed execute
go build -ldflags="-s -w" -trimpath perron2.ch/csvm
You can also use the associated makefile if you have make and UPX installed on your system. MacOS builds do currently not use UPX to compress the generated executable file due to an unresolved problem in UPX on macOS 13+.
make windows
make linux
make darwin
Rename two columns and map the possible values of the status column to something else:
csvm -mapfile mappings.txt original.csv mapped.csvThe mapping file mappings.txt being defined as:
id: code
name: title
status:
edit: 1
completed: 2
uploaded: 3The definitions in the mapping file cause the id column to be renamed to code, the name column to be renamed
to title and the values of the status column to be mapped to numeric values (without changing the column title).
In addition to mapping column titles and field values, this tool can be used to change the character set encoding and the field separator. The default values are the UTF-8 encoding and the comma for both the input CSV and the output CSV.
Convert a Windows ANSI (Windows-1252) CSV file with semicolon field separators to UTF-8 with comma separators:
csvm -inputcharset=ansi -inputseparator=";" original.csv converted.csvIn this example it is not necessary to specify -outputcharset=utf8 and -outputseparator="," because those
are the default values.