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

Print surrounding lines to understand matches without opening an editor.

Show lines before each match

Include preceding context lines.

bashANYripgrepcontextbefore
bash
rg -B 2 'panic!' src/

Useful for reading the setup or declaration that leads into a match.

Show lines after each match

Include following context lines.

bashANYripgrepcontextafter
bash
rg -A 3 'TODO' .

Often used to inspect comments, config blocks, or stack traces.

Show surrounding context

Print lines before and after each match.

bashANYripgrepcontext
bash
rg -C 2 'Exception' app.log

Context mode is a fast middle ground between plain search and opening the file.

Customize context separators

Make grouped output easier to parse visually.

bashANYripgrepcontextseparator
bash
rg -C 1 --context-separator '---' 'timeout' log.txt

Especially helpful in scripts or when pasting results into notes.

Print all lines but highlight matches

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

bashANYripgreppassthru
bash
rg --passthru -n 'ERROR|WARN' app.log

Good for presentations, log review, or quick visual filtering.

Formatting and location metadata

Tune filenames, headings, columns, and path formatting for humans or tools.

Disable file headings

Print file names inline per match instead of grouped headings.

bashANYripgrepno-heading
bash
rg --no-heading -n 'TODO' .

Many editors and scripts prefer one match per line with filename and line number.

Always show file names

Force file names even for a single file.

bashANYripgrepfilename
bash
rg --with-filename -n 'host' nginx.conf

Useful in scripts or when concatenating outputs from multiple commands.

Show column numbers

Include the column offset for each match.

bashANYripgrepcolumn
bash
rg --column 'SELECT' migrations/

Editor integrations often use filename, line, and column to jump to a result.

Print only the matched text

Return the matched substring instead of the full line.

bashANYripgreponly-matching
bash
rg -o '\b[A-F0-9]{8}\b' dump.txt

Great for extracting tokens, IDs, codes, or other bounded fragments.

Preview replacements in output

Show how a replacement would look without editing files.

bashANYripgrepreplacepreview
bash
rg -N --replace '$1_id' '([a-z]+)Id' src/

ripgrep does not rewrite files, but `--replace` is excellent for previewing transformations.

Reporting and scripting

Get summaries and structured output for automation and analysis.

Print summary statistics

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

bashANYripgrepstats
bash
rg --stats 'use client' app/

Useful when comparing search breadth or measuring refactor scope.

Use exit status only

Suppress output and rely on the exit code.

bashANYripgrepquietexit-code
bash
rg -q 'TODO' .

This is useful in shell scripts and CI checks.

Emit JSON events

Get begin, match, and end events in JSON.

bashANYripgrepjsonevents
bash
rg --json 'password' .

Structured output is safer than parsing human-readable text.

Normalize path separators

Choose a custom separator for path rendering.

bashANYripgreppath-separator
bash
rg --path-separator '/' 'TODO' .

Helpful when running on Windows but generating cross-platform output.

Limit matches per file

Stop after a fixed number of matches in each file.

bashANYripgrepmax-count
bash
rg -m 3 'deprecated' src/

Speeds up scans when you only need sample hits, not exhaustive results.

Recommended next

No recommendations yet.