Skip to main content

Grep

A powerful search tool for finding patterns in files with full regex support and multiple output modes.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.

Inputs

  • Pattern - string - Regular expression pattern to search for in file contents (required).
  • Path - string - File or directory to search in (optional, defaults to current directory).
  • Glob - string - Glob pattern to filter files, e.g., *.js or *.{ts,tsx} (optional).
  • Type - string - File type to search: js, py, rust, go, java, cpp, c, cs, php, rb, swift, kotlin, scala, sql, html, css, xml, json, yaml, md, txt (optional).
  • Output Mode - string - Output format: content (matching lines), files_with_matches (file paths only), count (match counts per file). Default: files_with_matches.
  • Head Limit - int - Limit output to first N lines/entries (optional, 0 = unlimited).
  • Before Context (-B) - int - Number of lines to show before each match (content mode only).
  • After Context (-A) - int - Number of lines to show after each match (content mode only).
  • Context (-C) - int - Number of lines to show before and after each match (overrides -A and -B).

Options

  • Case Insensitive (-i) - bool - Perform case-insensitive search (default: false).
  • Show Line Numbers (-n) - bool - Show line numbers in output for content mode (default: true).
  • Multiline - bool - Enable multiline mode where . matches newlines (default: false).
  • Max File Size - int - Maximum file size to search in bytes (default: 10485760 = 10MB).

Outputs

  • Result - array|string - Search results based on output mode (array for content/count, string array for files_with_matches).
  • Match Count - int - Total number of matches found.
  • File Count - int - Number of files containing matches.

How It Works

The Grep node searches for regex patterns across files and directories. When executed, the node:

  1. Validates and compiles the regex pattern
  2. Determines the search scope (file or directory)
  3. Applies filters: glob pattern, file type, max file size
  4. Searches through matched files
  5. Returns results based on output mode:
    • content: Returns matching lines with optional context
    • files_with_matches: Returns paths of files containing matches
    • count: Returns match count per file
  6. Applies head_limit if specified
  7. Returns statistics (match count, file count)

Requirements

  • Valid regex pattern
  • Read access to search path
  • For directory searches: traversable directory structure

Error Handling

The node will return specific errors in the following cases:

  • Missing pattern - "Pattern is required"
  • Invalid regex - "Invalid regex pattern: {{error}}"
  • Path access error - "Cannot access path: {{error}}"
  • File search error - "Error finding files: {{error}}"
  • Unknown file type - "Unknown file type: {{type}}"

Usage Examples

Search for Function Definitions

Find function definitions in Python files:

Pattern: def\s+\w+\(
Type: py
Output Mode: content
Show Line Numbers: true

Find All TODOs

Search for TODO comments across all JavaScript files:

Pattern: TODO:
Glob: **/*.js
Output Mode: content
Context (-C): 2
Case Insensitive: true

Find Files Containing Errors

Get list of log files containing errors:

Pattern: ERROR|FATAL
Path: /var/logs
Glob: *.log
Output Mode: files_with_matches

Count Imports

Count import statements per file:

Pattern: ^import\s
Type: py
Output Mode: count

Search with Context

Find specific configuration with surrounding lines:

Pattern: database\.host
Type: yaml
Output Mode: content
Before Context: 3
After Context: 3

Usage Notes

  • Regex uses Go's RE2 syntax (similar to PCRE but safer)
  • Hidden files (starting with .) are automatically skipped
  • Search stops at max file size to prevent memory issues
  • Context lines are numbered differently (marked with space instead of colon)
  • Multiline mode allows patterns to span multiple lines
  • File type filter is more efficient than glob for standard types
  • Head limit applies to output lines/entries, not matches
  • Results are returned immediately as they're found (up to head limit)

Supported File Types

  • js: .js, .jsx, .mjs
  • ts: .ts, .tsx
  • py: .py, .pyw
  • go: .go
  • rust: .rs
  • java: .java
  • cpp: .cpp, .cc, .cxx, .c++, .hpp, .h
  • c: .c, .h
  • cs: .cs
  • php: .php
  • rb: .rb
  • swift: .swift
  • kotlin: .kt, .kts
  • scala: .scala
  • sql: .sql
  • html: .html, .htm
  • css: .css, .scss, .sass, .less
  • xml: .xml, .xsl, .xslt
  • json: .json
  • yaml: .yaml, .yml
  • md: .md, .markdown
  • txt: .txt

Common Use Cases

Find function calls, class definitions, or specific patterns in source code.

Log Analysis

Search log files for errors, warnings, or specific events.

Configuration Auditing

Find configuration values across multiple config files.

Locate specific terms or patterns in documentation.

Dependency Analysis

Find import/require statements to understand dependencies.

Security Scanning

Search for potentially sensitive data or security issues.

Best Practices

  • Use file type filter for better performance on large codebases
  • Set appropriate max file size to avoid memory issues
  • Use glob patterns to narrow search scope
  • Enable case insensitive when searching for user input
  • Use context lines to understand matches better
  • Limit results with head_limit for large result sets
  • Test regex patterns before running on large directories
  • Combine with Glob node for complex file selection

Comparison with Other Nodes

  • Grep vs Glob: Grep searches file contents; Glob matches file names/paths
  • Grep vs Read: Grep searches across multiple files; Read reads single file
  • Grep vs Edit: Grep finds text; Edit replaces text