search
The search
command filters CSV data by whether the given regex matches a row.
Syntax
qsv search [options] <regex> [<input>]
Description
The search
command is used to filter CSV data by whether the given regex matches a row. This is useful for extracting specific subsets of data based on complex patterns.
Options
-i, --ignore-case
: Case insensitive search.--literal
: Treat the regex as a literal string.-s, --select <arg>
: Select the columns to search.-v, --invert-match
: Select only rows that did not match.-u, --unicode
: Enable unicode support.-f, --flag <column>
: Flag the found rows in a new column.-q, --quick
: Return on first match with an exitcode of 0.--preview-match <arg>
: Preview the first N matches or all the matches found in N milliseconds.-c, --count
: Return number of matches to stderr.--size-limit <mb>
: Set the approximate size limit (MB) of the compiled regular expression.--dfa-size-limit <mb>
: Set the approximate size of the cache (MB) used by the regular expression engine's Discrete Finite Automata.--json
: Output the result as JSON.--not-one
: Use exit code 0 instead of 1 for no match found.-h, --help
: Display this message.-o, --output <file>
: Write output to a file instead of stdout.-n, --no-headers
: When set, the first row will not be interpreted as headers.-d, --delimiter <arg>
: The field delimiter for reading CSV data.-p, --progressbar
: Show progress bars.-Q, --quiet
: Do not return number of matches to stderr.
Exit Codes
- 0: Operation successful or match found.
- 1: No match found, unless the '--not-one' flag is used.
- Non-zero: An error occurred.
Examples
Search for Term
Filter rows in a CSV file based on a regex pattern:
qsv search "Apartment" DLD_Transactions_English_500.csv | qsv table
Search in Specific Column
Filter rows in a specific column based on a regex pattern:
qsv search -s property_type_en "Apartment" DLD_Transactions_English_500.csv | qsv table
Common Use Cases
- Extracting specific subsets of data
- Filtering data based on complex patterns
Tips
- Verify the output to ensure the search is correctly applied
- Use in combination with other commands for complex data processing