Output, Context, and Reporting

Control headings, context lines, counts, paths, columns, and machine-readable output.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Context lines
Show lines before each match
rg -B 2 'panic!' src/

# Include preceding context lines.

Show lines after each match
rg -A 3 'TODO' .

# Include following context lines.

Show surrounding context
rg -C 2 'Exception' app.log

# Print lines before and after each match.

Customize context separators
rg -C 1 --context-separator '---' 'timeout' log.txt

# Make grouped output easier to parse visually.

Print all lines but highlight matches
rg --passthru -n 'ERROR|WARN' app.log

# Stream a file through rg without dropping non-matching lines.

## Formatting and location metadata
Disable file headings
rg --no-heading -n 'TODO' .

# Print file names inline per match instead of grouped headings.

Always show file names
rg --with-filename -n 'host' nginx.conf

# Force file names even for a single file.

Show column numbers
rg --column 'SELECT' migrations/

# Include the column offset for each match.

Print only the matched text
rg -o '\b[A-F0-9]{8}\b' dump.txt

# Return the matched substring instead of the full line.

Preview replacements in output
rg -N --replace '$1_id' '([a-z]+)Id' src/

# Show how a replacement would look without editing files.

## Reporting and scripting
Print summary statistics
rg --stats 'use client' app/

# Show counts and timing information at the end of a search.

Use exit status only
rg -q 'TODO' .

# Suppress output and rely on the exit code.

Emit JSON events
rg --json 'password' .

# Get begin, match, and end events in JSON.

Normalize path separators
rg --path-separator '/' 'TODO' .

# Choose a custom separator for path rendering.

Limit matches per file
rg -m 3 'deprecated' src/

# Stop after a fixed number of matches in each file.

Recommended next

No recommendations yet.