A few useful grep commands.

# Basic search:
grep <pattern> file

# To perform a case insensitive search:
grep -i <pattern> file

# Recursively grep for string <pattern> in folder:
grep -R <pattern> folder

# Getting pattern from file (one by line):
grep -f <pattern> file

# Find lines NOT containing <pattern>:
grep -v <pattern> file

# Using regular expressions:
grep "^00" file  # Match lines starting with 00
grep -E "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" file  # Find IP add

# Find all files who contain {pattern} in the directory {directory}.
# This will show: "file:line my research"
grep -rnw 'directory' -e "pattern"

# Exclude grep from your grepped output of ps.
# Add [] to the first letter. Ex: sshd -> [s]shd
ps aux | grep '[h]ttpd'

# Search for a given string in a file (case insensitive):
grep -i "the" demo_file

# Print the matched line, along with the 3 lines after it:
grep -A 3 -i "example" demo_text

# Search for a given string in all files recursively:
grep -r "ramesh" *

# Count line when words has been matched:
grep -c 'word' /path/to/file

# Only display filenames of matches:
grep -H -r "redeem reward" /home/tom

# Print all lines containing 'orange ' as a word
grep -w orange data.txt

# Use egrep to search 2 different words
egrep -w 'word1|word2' /path/to/file

# Search for keywork license (case-insensitve) in /dir/path/*, recursively
grep -i -r -s -C 3 'license' /dir/path/* --color

# Count line when words has been matched:
grep -c 'word' /path/to/file

# Precede each line of output with the number of the line matched in file:
grep -n 'root' /etc/passwd

# Print all line that do not contain the word bar (invert match):
grep -v bar /path/to/file

#  List the name of matching files:
grep -l 'main' *.c

# Hide all errors or warning messages generated by the grep command:
grep -w -R 'getMyData()' ~/projects/ 2>/dev/null

# More grep examples here:
# http://www.thegeekstuff.com/2009/03/15-practical-unix-grep-command-examples/