- Install
ripgrep
(rg
) andcolumn
(comes pre-installed on macOS):
brew install ripgrep
Use ripgrep
to quickly search for a keyword in your CSV file:
rg "your_search_term" yourfile.csv
rg
is a fast search tool, similar togrep
but optimized for large files."your_search_term"
is the keyword or pattern you want to search for.
To format the output into a table-like structure, use column
:
rg "your_search_term" yourfile.csv | column -s, -t
column -s, -t
uses-s,
to specify a comma as the delimiter and-t
to align the columns.
Ensure the header (first line) of the CSV is always included in the output:
{ head -n 1 yourfile.csv && rg "your_search_term" yourfile.csv; } | column -s, -t
head -n 1 yourfile.csv
grabs the first line (header) of the CSV.rg "your_search_term" yourfile.csv
searches the CSV for your term.{ ...; }
combines the header and search results.column -s, -t
formats the combined output into a readable table.
If your CSV file looks like this:
ID,ScreenName,Email
1,jdoe,[email protected]
2,asmith,[email protected]
3,jdoe,[email protected]
Running:
{ head -n 1 yourfile.csv && rg "jdoe" yourfile.csv; } | column -s, -t
Would produce:
ID ScreenName Email
1 jdoe [email protected]
3 jdoe [email protected]
ripgrep
(rg
) is blazingly fast, making it ideal for searching through large files.- Including the header ensures you always know what the columns represent.
- Using
column
creates a neatly formatted, readable output.
This setup is perfect for quick and efficient exploration of large CSV files directly from the command line.
Let me know if there's anything more you'd like to add!
Can also be saved & run as script: