.\" Man page generated from reStructuredText.
.
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "CSVGREP" "1" "Jul 12, 2024" "2.0.1" "csvkit"
.SH NAME
csvgrep \- csvgrep Documentation
.SH DESCRIPTION
.sp
Filter tabular data to only those rows where certain columns contain a given value or match a regular expression:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
usage: csvgrep [\-h] [\-d DELIMITER] [\-t] [\-q QUOTECHAR] [\-u {0,1,2,3}] [\-b]
               [\-p ESCAPECHAR] [\-z FIELD_SIZE_LIMIT] [\-e ENCODING] [\-S] [\-H]
               [\-K SKIP_LINES] [\-v] [\-l] [\-\-zero] [\-V] [\-n] [\-c COLUMNS]
               [\-m PATTERN] [\-r REGEX] [\-f MATCHFILE] [\-i] [\-a]
               [FILE]

Search CSV files. Like the Unix \(dqgrep\(dq command, but for tabular data.

positional arguments:
  FILE                  The CSV file to operate on. If omitted, will accept
                        input as piped data via STDIN.

optional arguments:
  \-h, \-\-help            show this help message and exit
  \-n, \-\-names           Display column names and indices from the input CSV
                        and exit.
  \-c COLUMNS, \-\-columns COLUMNS
                        A comma\-separated list of column indices, names or
                        ranges to be searched, e.g. \(dq1,id,3\-5\(dq.
  \-m PATTERN, \-\-match PATTERN
                        A string to search for.
  \-r REGEX, \-\-regex REGEX
                        A regular expression to match.
  \-f MATCHFILE, \-\-file MATCHFILE
                        A path to a file. For each row, if any line in the
                        file (stripped of line separators) is an exact match
                        of the cell value, the row matches.
  \-i, \-\-invert\-match    Select non\-matching rows, instead of matching rows.
  \-a  \-\-any\-match       Select rows in which any column matches, instead of
                        all columns.
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
See also: \fI\%Arguments common to all tools\fP\&.
.sp
NOTE: Even though \(aq\-m\(aq, \(aq\-r\(aq, and \(aq\-f\(aq are listed as \(dqoptional\(dq arguments, you must specify one of them.
.SH EXAMPLES
.sp
Search for the row relating to Illinois:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
csvgrep \-c 1 \-m ILLINOIS examples/realdata/FY09_EDU_Recipients_by_State.csv
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Search for rows relating to states with names beginning with the letter \(dqI\(dq:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
csvgrep \-c 1 \-r \(dq^I\(dq examples/realdata/FY09_EDU_Recipients_by_State.csv
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Search for rows that do not contain an empty state cell:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
csvgrep \-c 1 \-r \(dq^$\(dq \-i examples/realdata/FY09_EDU_Recipients_by_State.csv
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Perform a case\-insensitive search:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
csvgrep \-c 1 \-r \(dq(?i)illinois\(dq examples/realdata/FY09_EDU_Recipients_by_State.csv
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Remove comment rows:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
printf \(dqa,b\en1,2\en# a comment\en3,4\(dq | csvgrep \-\-invert\-match \-c1 \-r \(aq^#\(aq
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Get the indices of the columns that contain matching text (\fB\ex1e\fP is the \fI\%Record Separator (RS) character\fP):
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
csvgrep \-m 22 \-a \-c 1\- examples/realdata/FY09_EDU_Recipients_by_State.csv | csvformat \-M $\(aq\ex1e\(aq | xargs \-d $\(aq\ex1e\(aq \-n1 sh \-c \(aqecho $0 | csvcut \-n\(aq | grep 22
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
\fBNOTE:\fP
.INDENT 0.0
.INDENT 3.5
This last example is not performant.
.UNINDENT
.UNINDENT
.SH AUTHOR
Christopher Groskopf and contributors
.SH COPYRIGHT
2016, Christopher Groskopf and James McKinney
.\" Generated by docutils manpage writer.
.