What is the use of ‘grep’ command?

‘grep’ is a pattern search command. It searches for the pattern, specified in the command line with appropriate option, in a file(s). Syntax :      grep Example :    grep 99mx mcafile

Showing Answers 1 - 4 of 4 Answers

kishore kumar

  • Mar 31st, 2006

GREP is pattern checking command .

it will contain many option like -c and soon

it is very useful when checking for pattern from the file

  Was this answer useful?  Yes


  • Nov 21st, 2006

Grep - stands for Globally Search a Regular Expression and Print. It is used to search a given string/pattern under the given path and list out all the occurances of it in a file or set of files. Following are the options available for grep command. 1. grep "muru" . - this command search for the word "muru" in all the files under the current directory and print its occurances 2. grep -v "muru" sample.txt - this command prints all the lines in sample.txt that doesn't contain the string "muru" 3. grep -s "muru" sample.txt - this command suppresses error string if any 4. grep -n "muru" sample.txt - similar to example-1 but it also displays the line number along with the lines 5. grep -l "muru" . - similar to example-1 but here it will display only the name of the files which contains the string "muru" and not the lines it contains 6. grep -i "muru" . - similar to example-1 but it is case in sensitive 7. grep -c "muru" . - similar to example-1 it also displays total count (ie) total number of occurances of the string 8. grep -q "muru" . - if the string is found in any file then the command exit with value "0". It will not output anything. 9. grep -e "muru" -e "India" . - used to search more than one pattern at a time


  • Jun 3rd, 2010

When you want to  display the lines which do not start with #, then give following command ,

grep -v "^#" file1.txt

if you want to serach recursively in all the directories , then give ,

grep -r "string"

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions