grep
Search file contents for regex patterns with encoding detection, directory recursion, and context options to find specific text in files.
Instructions
Searches file contents for a regex pattern. Encoding-aware: auto-detects file encoding. Can search a single file or recursively search a directory. Output modes: content (default, matching lines), files_with_matches (paths only), count (match counts). Context: use before/after/context to include surrounding lines (like grep -B/-A/-C).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pattern | Yes | Regular expression pattern to search for | |
| path | No | File or directory to search in (absolute path). Defaults to current directory | |
| glob | No | Glob pattern to filter files (e.g. *.go). Only used when path is a directory | |
| ignore_case | No | Case insensitive search (default false) | |
| max_results | No | Maximum number of matching lines/files to return. Default: 100 | |
| output_mode | No | Output mode: 'content' (matching lines with path:line:text, default), 'files_with_matches' (file paths only), 'count' (match count per file) | |
| context | No | Lines of context before and after each match (like grep -C). Default: 0 | |
| before | No | Lines of context before each match (like grep -B). Overrides context. Default: 0 | |
| after | No | Lines of context after each match (like grep -A). Overrides context. Default: 0 |