phrs — the tabular data shell tool
phrs is a Rust command-line tool for manipulating CSV data in Unix pipelines. It is inspired by ph and uses Polars for tabular operations.
Install
Getting started
Suppose a.csv contains:
x,y
3,8
4,9
5,10
6,11
7,12
8,13
Commands usually read CSV from standard input and write CSV to standard output, so they can be chained:
| |
y,x
8,3
9,4
10,5
To display a human-readable table, use show:
|
x y
-- --- ---
0 3 8
1 4 9
2 5 10
3 6 11
4 7 12
5 8 13
show produces terminal output rather than CSV; it is normally the last command in a pipeline.
Commands
Inspect and select columns
| | |
Select and order rows
| |
| |
|
Rename and clean columns
| | | |
Filter rows with query
query supports simple column-to-value comparisons (==, !=, <, <=, >, >=):
|
|
Compute columns with eval
eval supports arithmetic expressions, assignments, numeric constants, parentheses, and exponentiation:
|
|
|
|
Display a table
|
|
Concatenate CSV files
Unlike most commands, cat takes filenames. With no filenames, it reads standard input.
|
Merge CSV files
merge reads two named CSV files and joins their rows. The default join type is inner; supported types are inner, left, right, and outer.
When no join key is provided, common column names are used as join keys.
Pipelines
| | | | |
Development
The optimized executable is written to target/release/phrs.
phrs aims to reproduce the behavior of the Python ph tool for its implemented commands, but does not yet support every ph operation. Differences are tracked using differential tests against the Python implementation.
License
MIT.