Skip to main content
The kdx document grep and kdx document lines commands provide Unix-style text search and line retrieval for KDDB files. Output is JSON Lines format by default, ideal for piping through jq and building shell pipelines.

Grep Command

Search document content for lines matching a pattern, similar to Unix grep.

Flags

Find all lines containing a text pattern:
Use -E for extended regex patterns:

Context Lines

Show surrounding lines for context:

Count Matches

Get just the count of matching lines:

Limit Results

Stop after finding N matches:

Filter by Page

Search only on a specific page:

Pretty Print

For debugging, use pretty-printed JSON:

Lines Command

Retrieve specific lines by index range, page number, or UUID.

Flags

Lines by Index Range

Get lines by their 0-based index (exclusive end, like Python slicing):

Lines by Page

Get all lines from a specific page:

Lines by UUID

Get specific lines by their UUID:

All Lines

Without flags, returns all lines in the document:

Output Format

Both commands output JSON Lines (JSONL) format by default - one JSON object per line:

Output Fields

Shell Pipeline Examples

Extract UUIDs from Search Results

Count Matches per Page

Get Content from UUIDs

Extract Lines from Multiple Pages

Filter and Transform

Build Context for LLM

Search and Retrieve Full Context

Use Cases

Document Search and Analysis

Quickly search across document content:

Building LLM Prompts

Extract relevant content for LLM context windows:

Data Pipeline Integration

Use in automated workflows:

Quality Assurance

Validate document content:

Tips

Use -E (extended regex) when you need pattern matching. Without it, special characters like . and * are treated literally.
JSON Lines format streams well - you can process results as they arrive without loading everything into memory.
Combine grep with --max to quickly check if a pattern exists without processing the entire document.
The uuid field comes from the spatial:uuid feature on line nodes. Documents without this feature will have empty UUIDs.
Page numbers are 1-based in the output and flags, matching how users typically refer to pages.

Document Structure

Print and select commands for structure inspection

Document Overview

All document commands

SDK: Selectors

Programmatic node selection