grep Verified for v3.11 LTS

Grep Command: Print Only The Matched Text

An engineer might use the grep command with the '-o' option to extract and display only the specific matching substrings from large log files or source code during a debugging session. Exact CLI syntax to print only the matched text using Grep.

When to use this: An engineer might use the grep command with the '-o' option to extract and display only the specific matching substrings from large log files or source code during a debugging session.

Command Syntax

grep -o "<search_pattern>" <path/to/file>

Command Breakdown

-o
Only Matching
Prints only the matching part of the line.

FAQ

Purpose: Exact syntax to print only the matched text using Grep.

Test path: Replace placeholders and run destructive commands in a disposable workspace first.

Flag behavior: Tool version, platform, and shell can change behavior.

Improve This Command

Suggest a correction, safer default, or version-specific note for this entry.

Related Operations

Back to Grep directory