1CSV(1)                User Contributed Perl Documentation               CSV(1)
2
3
4

NAME

6       csv - process CSV files from the command line
7

SYNOPSIS

9         # On the command line:
10
11         csv 1 2 -1 < report.csv
12
13         # Reads the first two fields, as well as the last one, from "report.csv".
14         # Data is cleaned up and emitted as CSV.
15
16         csv --fields Revenue,Q1,Q2 < report.csv   # or "-f" for short
17
18         # First line of the input (from file "report.csv") is considered as
19         # header line; the fields are emitted in the order "Revenue", "Q1",
20         # and "Q2". Data is cleaned up and emitted as CSV.
21
22         csv --input report.csv --to_tsv
23
24         # Converts the whole report to TSV (tab-separated values).
25

DESCRIPTION

27       CSV (comma-separated value) files are the lowest common denominator of
28       structured data interchange formats. For such a humble file format, it
29       is pretty difficult to get right: embedded quote marks and linebreaks,
30       slipshod delimiters, and no One True Validity Test make CSV data found
31       in the wild hard to parse correctly. Text::CSV_XS provides flexible and
32       performant access to CSV files from Perl, but is cumbersome to use in
33       one-liners and the command line.
34
35       csv is intended to make commandline processing of CSV files as easy as
36       plain text is meant to be on Unix. Internally, it holds two Text::CSV
37       objects (for input and for output), which have reasonable defaults but
38       which you can reconfigure to suit your needs. Then you can extract just
39       the fields you want, change the delimiter, clean up the data etc.
40
41       In the simplest usage, csv filters stdio and takes a list of integers.
42       These are 1-based column numbers to select from the input CSV stream.
43       Negative numbers are counted from the line end. Without any column
44       list, csv selects all columns (this is still useful to normalize
45       quoting style etc.).
46
47   Command line options
48       The following options are passed to Text::CSV. When preceded by the
49       prefix "output_", the destination is affected. Otherwise these options
50       affect both input and output.
51
52       --quote_char
53       --escape_char
54       --sep_char
55       --eol
56       --always_quote
57       --binary
58       --keep_meta_info
59       --allow_loose_quotes
60       --allow_loose_escapes
61       --allow_whitespace
62       --verbatim
63
64       NOTE: binary is set to 1 by default in csv. The other options have
65       their Text::CSV defaults.
66
67       The following additional options are available:
68
69       --input, -i
70       --output, -o
71           Filenames for input and output. "-" means stdio. Useful to trigger
72           TSV mode ("--from_tsv" and "--to_tsv").
73
74       --columns, -c
75           Column numbers may be specified using this option.
76
77       --fields, -f
78           When this option is specified, the first line of the input file is
79           considered as a header line. This option takes a comma-separated
80           list of column-names from the first line.
81
82           For convenience, this option also accepts a comma-separated list of
83           column numbers as well. Multiple --fields options are allowed, and
84           both column names and numbers can be mixed together.
85
86       --from_tsv, --from-tsv
87       --to_tsv, --to-tsv
88           Use tabs instead of commas as the delimiter. When csv has the input
89           or output filenames available, this is inferred when they end with
90           ".tsv".  To disable this dwimmery, you may say "--to_tsv=0" and
91           "--from_tsv=0".
92

SEE ALSO

94       Text::CSV, Text::CSV_XS
95

AUTHOR

97       Gaal Yahas "<gaal@forum2.org>"
98

THANKS

100       nothingmuch, gphat, t0m, themoniker, Prakash Kailasa, tsibley, srezic,
101       and ether.
102

BUGS

104       Please report any bugs or feature requests to "bug-app-csv at
105       rt.cpan.org", or through the web interface at
106       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-CSV>.  I will be
107       notified, and then you'll automatically be notified of progress on your
108       bug as I make changes.
109
110       You're also invited to work on a patch. The source repo is at
111
112       <git://github.com/gaal/app-csv.git>
113
114       <http://github.com/gaal/app-csv/tree/master>
115
117       Copyright 2013 Gaal Yahas.
118
119       Permission is hereby granted, free of charge, to any person obtaining a
120       copy of this software and associated documentation files (the
121       "Software"), to deal in the Software without restriction, including
122       without limitation the rights to use, copy, modify, merge, publish,
123       distribute, sublicense, and/or sell copies of the Software, and to
124       permit persons to whom the Software is furnished to do so, subject to
125       the following conditions:
126
127       The above copyright notice and this permission notice shall be included
128       in all copies or substantial portions of the Software.
129
130       THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
131       OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
132       MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
133       IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
134       CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
135       TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
136       SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
137
138
139
140perl v5.38.0                      2023-07-20                            CSV(1)
Impressum