recsel

Query and filter GNU recutils database records

TLDR

Select all records from a recfile
$ recsel [file.rec]
Select records matching a condition
$ recsel -e "[field] = '[value]'" [file.rec]
Select records with multiple conditions
$ recsel -e "[field1] = '[value]' && [field2] > [number]" [file.rec]
Select specific fields only
$ recsel -p [field1],[field2] [file.rec]
Select records from a specific type
$ recsel -t [record_type] [file.rec]
Count matching records
$ recsel -c -e "[condition]" [file.rec]
Sort records by a field
$ recsel -S [field] [file.rec]

SYNOPSIS

recsel [options] [-e expression] [-t type] [file...]

DESCRIPTION

recsel is part of GNU Recutils, a set of tools for managing plain-text databases using the rec format. It selects and prints records from recfiles based on expressions and criteria.Recfiles are human-readable text files where each record is a collection of named fields separated by blank lines. The format is simple, versionable with git, and editable with any text editor.Selection expressions support comparison operators (=, !=, <, >, <=, >=), logical operators (&&, ||, !), pattern matching (~), and field existence checks. Expressions operate on field values within each record.Output can be restricted to specific fields with -p, sorted with -S, and limited with -n. The tool handles multiple record types within a single file using -t.

PARAMETERS

-e expression

Select records matching the expression
-t type
Select records of specified type only
-p fields
Print only specified fields (comma-separated)
-P fields
Print specified fields without record separators
-c, --count
Print count of matching records
-C, --collapse
Collapse multiple field values into one
-S field
Sort records by specified field
-G field
Group records by specified field
-n max
Return at most max records
-R random
Return random records
-d, --print-descriptors
Print record descriptors

EXPRESSION SYNTAX

field = "value": Exact string matchfield ~ "pattern": Regular expression matchfield < number: Numeric comparisonfield && field2: Logical AND#field: Field exists!#field: Field does not exist

INSTALL

sudo dnf install recutils
sudo apk add recutils
brew install recutils
nix profile install nixpkgs#recutils

CAVEATS

Field names and string values in expressions must follow recutils quoting rules. Strings with spaces require quotes.Numeric comparisons require fields to contain valid numbers. Non-numeric values cause comparison failures.Large recfiles may be slow to process compared to proper databases, but the simplicity and portability often outweigh performance concerns for moderate data sizes.

SEE ALSO

recins(1), recdel(1), recset(1), recfmt(1), rec2csv(1)