With -s. Each takes one value, and they can be in any order.
Flag
Meaning
-w CONDITION, --where CONDITION
Only rows matching CONDITION, e.g. -w 'age > 40'. Repeat it to require every condition
-g COLUMNS, --group COLUMNS
One row per distinct value of COLUMNS, for use with count(*), sum() and the like
-o COLUMNS, --order COLUMNS
Sort by COLUMNS, e.g. -o name or -o 'age desc'
-l COUNT, --limit COUNT
Return at most COUNT rows
-q CLAUSES, --query CLAUSES
Everything from 'where' to the end as one SQL string, instead of -w, -g, -o and -l
Modifiers
Flag
Meaning
-a, --all
With -s, select all columns, so COLUMNS is left out
-f, --file
Query a data file directly (the default, and the only mode so far)
-d CHAR, --delimiter CHAR
Field delimiter for input and output, e.g. ';' or '\t' (default ',')
-t COLUMNS, --text COLUMNS
Keep these columns as text even if they look like numbers, e.g. -t zip or -t 'zip, $4'
-H, --no-header
The first line is data; refer to columns as $1, $2...
Other
Flag
Meaning
-h, --help
Show this help message and exit
-V, --version
Show the version and exit
Arguments, examples and exit status
arguments:
FILE the data file to query. Leave it out, or use -, to read
standard input
COLUMNS with -s, the columns to select, as one argument:
name,job or 'name, $3'
STATEMENT without -s, a whole select statement in one set of quotes
examples:
datapy -sa people.csv
datapy -sa people.csv -w 'age > 40' -o name
datapy -sa people.csv -o 'age desc' -l 10
datapy -s 'job, count(*)' people.csv -g job
datapy -sa people.csv -q 'where age > 40 order by name'
datapy 'select name, job from people.csv where age > 40'
cat people.csv | datapy -sa -w '$2 > 40' | head
Rows are read and written as they go, so a query that only picks columns and
filters rows (-s, -w, -l) uses a small, fixed amount of memory on a file of
any size. Sorting, grouping and counting need every row first: those load
the file into a temporary database on disk, not into memory.
A column is treated as a number when every value in its first 1,000 rows is
one. Use -t to keep a column as text.
Put each value in single quotes. Without them the shell treats > and < as
redirects and expands * and $1. Use double quotes when the value contains
text in single quotes:
datapy -sa people.csv -w "name = 'Ann'"
exit status: 0 on success, 1 if the query or file is invalid, 2 on a usage error.