What is the purpose of the 'grep' command?

QuestionsQuestions8 SkillsProLinux Data PipingOct, 23 2025
0111

The grep command is used in Unix/Linux systems to search for specific patterns within files or input provided to it. It stands for "global regular expression print." The command scans the input line by line and prints lines that match the specified pattern. It is commonly used for searching text in files, filtering output, and processing data in command-line environments.

Basic Syntax

grep [options] pattern [file...]

Example

To search for the word "example" in a file named file.txt, you would use:

grep "example" file.txt

Common Options

  • -i: Ignore case distinctions.
  • -r: Recursively search directories.
  • -v: Invert the match, showing lines that do not match the pattern.
  • -n: Show line numbers with output lines.

This command is very powerful for text processing and data analysis in scripts and command-line operations.

0 Comments

no data
Be the first to share your comment!