| 1 |
========= |
| 2 |
csvformat |
| 3 |
========= |
| 4 |
|
| 5 |
Description |
| 6 |
=========== |
| 7 |
|
| 8 |
Convert a CSV file to a custom output format.: |
| 9 |
|
| 10 |
.. code-block:: none |
| 11 |
|
| 12 |
usage: csvformat [-h] [-d DELIMITER] [-t] [-q QUOTECHAR] [-u {0,1,2,3}] [-b] |
| 13 |
[-p ESCAPECHAR] [-z FIELD_SIZE_LIMIT] [-e ENCODING] |
| 14 |
[-L LOCALE] [-S] [-H] [-K SKIP_LINES] [-v] [-l] [--zero] [-V] |
| 15 |
[-E] [-D OUT_DELIMITER] [-T] [-A] [-Q OUT_QUOTECHAR] |
| 16 |
[-U {0,1,2,3}] [-B] [-P OUT_ESCAPECHAR] |
| 17 |
[-M OUT_LINETERMINATOR] |
| 18 |
[FILE] |
| 19 |
|
| 20 |
Convert a CSV file to a custom output format. |
| 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 |
-E, --skip-header Do not output a header row. |
| 29 |
-D OUT_DELIMITER, --out-delimiter OUT_DELIMITER |
| 30 |
Delimiting character of the output file. |
| 31 |
-T, --out-tabs Specify that the output file is delimited with tabs. |
| 32 |
Overrides "-D". |
| 33 |
-A, --out-asv Specify that the output file is delimited with the |
| 34 |
ASCII unit separator and record separator. Overrides |
| 35 |
"-T", "-D" and "-M". |
| 36 |
-Q OUT_QUOTECHAR, --out-quotechar OUT_QUOTECHAR |
| 37 |
Character used to quote strings in the output file. |
| 38 |
-U {0,1,2,3}, --out-quoting {0,1,2,3} |
| 39 |
Quoting style used in the output file: 0 quote |
| 40 |
minimal, 1 quote all, 2 quote non-numeric, 3 quote |
| 41 |
none. |
| 42 |
-B, --out-no-doublequote |
| 43 |
Whether or not double quotes are doubled in the output |
| 44 |
file. |
| 45 |
-P OUT_ESCAPECHAR, --out-escapechar OUT_ESCAPECHAR |
| 46 |
Character used to escape the delimiter in the output |
| 47 |
file if --quoting 3 ("Quote None") is specified and to |
| 48 |
escape the QUOTECHAR if --out-no-doublequote is |
| 49 |
specified. |
| 50 |
-M OUT_LINETERMINATOR, --out-lineterminator OUT_LINETERMINATOR |
| 51 |
Character used to terminate lines in the output file. |
| 52 |
|
| 53 |
See also: :doc:`../common_arguments`. |
| 54 |
|
| 55 |
Examples |
| 56 |
======== |
| 57 |
|
| 58 |
Convert a comma-separated file to a pipe-delimited file: |
| 59 |
|
| 60 |
.. code-block:: bash |
| 61 |
|
| 62 |
csvformat -D "|" examples/dummy.csv |
| 63 |
|
| 64 |
Convert to carriage return line-endings: |
| 65 |
|
| 66 |
.. code-block:: bash |
| 67 |
|
| 68 |
csvformat -M $'\r' examples/dummy.csv |
| 69 |
|
| 70 |
Convert to a tab-delimited file (TSV) with no doubling of double quotes: |
| 71 |
|
| 72 |
.. code-block:: bash |
| 73 |
|
| 74 |
printf 'key,value\n1,"a ""quoted"" string"' | csvformat -T -Q🐍 |
| 75 |
|
| 76 |
To avoid escaping quote characters when using :code:`--quoting 3`, add :code:`--out-quotechar ""`: |
| 77 |
|
| 78 |
.. code-block:: bash |
| 79 |
|
| 80 |
csvformat -u3 -U3 -Q🐍 examples/optional_quote_characters.csv |