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.
