csvgrep
TLDR
Filter rows by column matching a value
SYNOPSIS
csvgrep [options] file
DESCRIPTION
csvgrep is part of csvkit that filters CSV rows based on column values. Unlike standard grep, it understands CSV structure and can match against specific columns while preserving proper CSV output.
The tool supports both exact string matching and regular expressions. Multiple columns can be searched, and the match sense can be inverted to exclude rows. This makes it ideal for extracting subsets of data based on criteria.
csvgrep handles quoted fields correctly, ensuring that commas within fields don't break the search. Results include the header row, maintaining valid CSV structure.
PARAMETERS
-c COLUMN, --columns COLUMN
Column name(s) or index to search (comma-separated for multiple).-m STRING, --match STRING
Exact string to search for.-r REGEX, --regex REGEX
Regular expression pattern to match.-f FILE, --file FILE
File containing values to match (one per line).-i, --invert-match
Select non-matching rows.-a, --any-match
Match if any column matches (with multiple columns).-d CHAR, --delimiter CHAR
Field delimiter (default: comma).-e ENCODING, --encoding ENCODING
Input file encoding.
CAVEATS
Regular expressions use Python syntax. Column names are case-sensitive. Large files may be slow as the entire file is processed. Memory usage scales with file size for some operations.
HISTORY
csvgrep is part of csvkit, created by Christopher Groskopf in 2011. It provides grep-like functionality aware of CSV structure, solving the common problem of searching tabular data without breaking on embedded delimiters.


