LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

csvgrep

CSV row filter by column values

TLDR

Filter rows by column matching a value
$ csvgrep -c [column] -m "[value]" [data.csv]
copy
Filter using regular expression
$ csvgrep -c [column] -r "[pattern]" [data.csv]
copy
Filter by column number instead of name
$ csvgrep -c [1] -m "[value]" [data.csv]
copy
Invert match (exclude matching rows)
$ csvgrep -c [column] -m "[value]" -i [data.csv]
copy
Match against multiple columns
$ csvgrep -c "[col1,col2]" -m "[value]" [data.csv]
copy
Case-insensitive matching
$ csvgrep -c [column] -r "(?i)[pattern]" [data.csv]
copy

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.

SEE ALSO

csvcut(1), csvsort(1), grep(1), csvkit(1)

RESOURCES

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid