Debian Codegraph @

docs/scripts/csvsort.rst

raw
1 =======
2 csvsort
3 =======
4
5 Description
6 ===========
7
8 Sort CSV files. Like the Unix "sort" command, but for tabular data:
9
10 .. code-block:: none
11
12 usage: csvsort [-h] [-d DELIMITER] [-t] [-q QUOTECHAR] [-u {0,1,2,3}] [-b]
13 [-p ESCAPECHAR] [-z FIELD_SIZE_LIMIT] [-e ENCODING] [-L LOCALE]
14 [-S] [--blanks] [--null-value NULL_VALUES [NULL_VALUES ...]]
15 [--date-format DATE_FORMAT] [--datetime-format DATETIME_FORMAT]
16 [-H] [-K SKIP_LINES] [-v] [-l] [--zero] [-V] [-n] [-c COLUMNS]
17 [-r] [-i] [-y SNIFF_LIMIT] [-I]
18 [FILE]
19
20 Sort CSV files. Like the Unix "sort" command, but for tabular data.
21
22 positional arguments:
23 FILE The CSV file to operate on. If omitted, will accept
24 input as piped data via STDIN.
25
26 optional arguments:
27 -h, --help show this help message and exit
28 -n, --names Display column names and indices from the input CSV
29 and exit.
30 -c COLUMNS, --columns COLUMNS
31 A comma-separated list of column indices, names or
32 ranges to sort by, e.g. "1,id,3-5". Defaults to all
33 columns.
34 -r, --reverse Sort in descending order.
35 -i, --ignore-case Perform case-independent sorting.
36 -y SNIFF_LIMIT, --snifflimit SNIFF_LIMIT
37 Limit CSV dialect sniffing to the specified number of
38 bytes. Specify "0" to disable sniffing entirely, or
39 "-1" to sniff the entire file.
40 -I, --no-inference Disable type inference (and --locale, --date-format,
41 --datetime-format, --no-leading-zeroes) when parsing
42 the input.
43
44 See also: :doc:`../common_arguments`.
45
46 .. note::
47
48 If your file is large, try :code:`sort -t, file.csv` instead.
49
50 Examples
51 ========
52
53 Sort the veteran's education benefits table by the "TOTAL" column:
54
55 .. code-block:: bash
56
57 csvsort -c 9 examples/realdata/FY09_EDU_Recipients_by_State.csv
58
59 View the five states with the most individuals claiming veteran's education benefits:
60
61 .. code-block:: bash
62
63 csvcut -c 1,9 examples/realdata/FY09_EDU_Recipients_by_State.csv | csvsort -r -c 2 | head -n 5