1CSVCUT(1)                           csvkit                           CSVCUT(1)
2
3
4

NAME

6       csvcut - csvcut Documentation
7

DESCRIPTION

9       Filters  and  truncates CSV files. Like the Unix “cut” command, but for
10       tabular data:
11
12          usage: csvcut [-h] [-d DELIMITER] [-t] [-q QUOTECHAR] [-u {0,1,2,3}] [-b]
13                        [-p ESCAPECHAR] [-z FIELD_SIZE_LIMIT] [-e ENCODING] [-S] [-H]
14                        [-K SKIP_LINES] [-v] [-l] [--zero] [-V] [-n] [-c COLUMNS]
15                        [-C NOT_COLUMNS] [-x]
16                        [FILE]
17
18          Filter and truncate CSV files. Like the Unix "cut" command, but for tabular
19          data.
20
21          positional arguments:
22            FILE                  The CSV file to operate on. If omitted, will accept
23                                  input on STDIN.
24
25          optional arguments:
26            -h, --help            show this help message and exit
27            -n, --names           Display column names and indices from the input CSV
28                                  and exit.
29            -c COLUMNS, --columns COLUMNS
30                                  A comma separated list of column indices, names or
31                                  ranges to be extracted, e.g. "1,id,3-5". Defaults to
32                                  all columns.
33            -C NOT_COLUMNS, --not-columns NOT_COLUMNS
34                                  A comma separated list of column indices, names or
35                                  ranges to be excluded, e.g. "1,id,3-5". Defaults to no
36                                  columns.
37            -x, --delete-empty-rows
38                                  After cutting, delete rows which are completely empty.
39
40       See also: ../common_arguments.
41
42       NOTE:
43          csvcut does not implement row filtering, for this  you  should  pipe
44          data to csvgrep.
45
46       NOTE:
47          If  a data row is longer than the header row, its additional columns
48          are truncated. Use csvclean first to fix such rows.
49

EXAMPLES

51       Print the indices and names of all columns:
52
53          csvcut -n examples/realdata/FY09_EDU_Recipients_by_State.csv
54            1: State Name
55            2: State Abbreviate
56            3: Code
57            4: Montgomery GI Bill-Active Duty
58            5: Montgomery GI Bill- Selective Reserve
59            6: Dependents' Educational Assistance
60            7: Reserve Educational Assistance Program
61            8: Post-Vietnam Era Veteran's Educational Assistance Program
62            9: TOTAL
63           10:
64
65       Print only the names of all columns, by removing the indices  with  the
66       cut command:
67
68          csvcut -n examples/realdata/FY09_EDU_Recipients_by_State.csv | cut -c6-
69          State Name
70          State Abbreviate
71          Code
72          Montgomery GI Bill-Active Duty
73          Montgomery GI Bill- Selective Reserve
74          Dependents' Educational Assistance
75          Reserve Educational Assistance Program
76          Post-Vietnam Era Veteran's Educational Assistance Program
77          TOTAL
78
79       Extract the first and third columns:
80
81          csvcut -c 1,3 examples/realdata/FY09_EDU_Recipients_by_State.csv
82
83       Extract columns named “TOTAL” and “State Name” (in that order):
84
85          csvcut -c TOTAL,"State Name" examples/realdata/FY09_EDU_Recipients_by_State.csv
86
87       Add line numbers to a file, making no other changes:
88
89          csvcut -l examples/realdata/FY09_EDU_Recipients_by_State.csv
90
91       Extract a column that may not exist in all files:
92
93          echo d, | csvjoin examples/dummy.csv - | csvcut -c d
94          echo d, | csvjoin examples/join_no_header_row.csv - | csvcut -c d
95
96       Display a column’s unique values:
97
98          csvcut -c 1 examples/realdata/FY09_EDU_Recipients_by_State.csv | sed 1d | sort | uniq
99
100       Or:
101
102          csvcut -c 1 examples/realdata/FY09_EDU_Recipients_by_State.csv | csvsql --query 'SELECT DISTINCT("State Name") FROM stdin'
103

AUTHOR

105       Christopher Groskopf
106
108       2020, Christopher Groskopf
109
110
111
112
1131.0.4                            Jan 30, 2020                        CSVCUT(1)
Impressum