The grep command is a powerful text search utility in Unix and Linux systems. It stands for "Global Regular Expression Print" and is used to search for specific patterns within files or input provided to it. Here are some key features and uses of the grep command:
Pattern Matching:
grepsearches for lines that match a specified pattern, which can be a simple string or a more complex regular expression.File Searching: You can use
grepto search through one or more files for the specified pattern.Output: By default,
grepprints the lines that contain the matching pattern to the standard output.Options:
grephas various options to modify its behavior, such as:-i: Ignore case (case-insensitive search).-v: Invert the match (show lines that do not match the pattern).-r: Recursively search through directories.-n: Show line numbers with output lines.
Example Usage:
To search for the word "example" in a file named file.txt, you would use:
grep 'example' file.txt
This command will display all lines in file.txt that contain the word "example".
