How To Use The Grep Command?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Grep is a command-line utility for searching plain-text data sets for lines that match a specific pattern. It is commonly used in Unix-like and Linux-based operating systems.
To use the grep command, open the terminal in your system and type in the following command:
grep [options] pattern [file]
Options:
-i: Ignore case distinctions in both the PATTERN and the input files
-v: Select non-matching lines
-r: Read all files under each directory recursively
-w: Match only whole words
-A NUM: Print NUM lines of trailing context after matching lines
-B NUM: Print NUM lines of leading context before matching lines
-C NUM: Print NUM lines of output context
Example:
grep -i ‘example’ text.txt
This command searches the text.txt file for lines containing the word “example” in any case.