csvkitHow to split a csv file with csvkit?
csvkit is a suite of command-line tools for working with CSV, the most popular being csvcut
and csvsplit
.
csvcut
can be used to select specific columns from a CSV file, while csvsplit
can be used to split a CSV file into multiple files based on a given column.
Example code
csvcut -c 1,2,3 input.csv > output.csv
csvsplit -c 3 input.csv
Output of example code:
input.csv
1,2,3
4,5,6
7,8,9
output.csv
1,2,3
4,5,6
7,8,9
input_3_1.csv
1,2,3
4,5,6
input_3_2.csv
7,8,9
Code explanation
csvcut
: used to select specific columns from a CSV file-c
: used to specify the columns to be selectedcsvsplit
: used to split a CSV file into multiple files based on a given column-c
: used to specify the column to split on
Helpful links
More of Csvkit
- How to update specific records using csvkit?
- How to fetch unique values with csvkit?
- How to convert a tsv file to csv with csvkit?
- How to rename a column with csvkit?
- How to convert a json file to csv with csvkit?
- How to convert a csv file to tab delimited with csvkit?
- How to remove duplicates with csvkit?
- How to sort a csv file with csvkit?
- How to skip the first line with csvkit?
See more codes...