Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

3 Commits

Repository files navigation

cora

Tip my tokens

Multi-pattern fixed-string matcher. Searches files or stdin for one or more literal patterns using Aho-Corasick. Outputs NDJSON.

Requirements

  • Rust 1.70+ (uses edition 2021)

Install

cargo build --release
cp target/release/cora ~/.local/bin/

Usage

cora [OPTIONS] <PATTERNS...> [-- FILES...]

Patterns can be labeled: err=ERROR produces matches tagged with the label err. Without a label, matches use the 0-based pattern index.

Reads from stdin when no files are given.

Options

FlagShortDescription
--verbose-vFull-key NDJSON output
--insensitive-iCase-insensitive matching
--context N-C NInclude N lines before/after each match
--max-matches N-M NStop after N matches (0 = unlimited)
--count-cSummary only, no match lines
--pattern-file PATH-f PATHRead patterns from file (one per line, label=pattern, # comments)
--describeEmit JSON capability manifest and exit

Output

Each match is one JSON line. Default mode uses short keys:

KeyTypeDescription
pintPattern index (0-based)
nstring?Pattern label (if provided)
lintLine number (1-based)
cintColumn (1-based)
bintByte offset from start of file/stream
mstringMatched text
tstringFull line text
fstring?File path (omitted for stdin)
cbstring[]?Context lines before (omitted when empty)
castring[]?Context lines after (omitted when empty)

Both modes are lossless — same fields, different key names. With -v, keys expand:

TuneVerbose
ppattern_id
nlabel
lline
ccolumn
bbyte_offset
mmatch
ttext
fpath
cbcontext_before
cacontext_after

The last line is always a summary:

{"_":"summary","n":42,"tr":false,"files":{"app.log":{"n":42,"sz":8192}},"pats":{"err":30,"warn":12}}

Examples

# Search stdinecho'connection error detected'| cora error warning
# Search files with labeled patterns
cora 'err=ERROR''warn=WARN' -- app.log server.log
# Case-insensitive with context
cora -i -C 2 error -- app.log
# Count only
cora -c ERROR WARN -- *.log
# Patterns from file
cora -f patterns.txt -- app.log
# Machine-readable self-description
cora --describe

Dependencies

CratePurpose
aho-corasickMulti-pattern matching
clapCLI argument parsing
memmap2Memory-mapped file I/O
memchrSIMD byte search
itoaInteger formatting
serde / serde_jsonSummary serialization
anyhowError handling

License

MIT

About

Multi-pattern fixed-string matcher. Aho-Corasick + SIMD on mmap'd files. NDJSON output for AI agents and pipelines.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages