grep
What is grep? grep is using to print lines matching a pattern.
grep syntax:
grep [options] pattern [file]
In the syntax, the pattern would be RE and strings.If the string was used,there would be double quotation marks.For including double quotations around string, we could not be confused by the string which would be considered as SHELL command if there are not quotations,and the string such as “get up” including backspace would also be recognized. When there are variables, the quotations should not be missed.
some option paramters:
-c : only print the count of matching lines per file.
-i : ignore case distinctions
-n : print line number of out lines.
-s : suppress error messages
-v : select non-matched lines.
“>” is used to accuracy matching.This is very important.
+E option supports the “AND” and “OR” matching patterns.For example,if we would to find 219 or 216, the following command is used: # grep +E ‘219|216’ testfile
Note,if there is not single quotations,just like “grep +E 219|216 testfile”.This string is considered as SHELL command, and the error messages were displayed(in Mandriva):
# grep +E 219|216 testfile
bash: 234: command not found.
Some useful commands about grep:
# ls -l | grep ‘^d’
# grep ‘username’ /etc/passwd
# ps -ax | grep “named”
This command is used to identify if the DNS server (named) had been running.
# STR = “Mary Joe Peter Paulin”
# echo $ STR | grep “Mary”
output file: Mary Joe Peter Paulin
egrep: extended grep, it is alwayed used with “-f ” option.