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 Unixgrep.
Flags
Basic Search
Find all lines containing a text pattern:Case-Insensitive Search
Regex Search
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
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.
Related
Document Structure
Print and select commands for structure inspection
Document Overview
All document commands
SDK: Selectors
Programmatic node selection
