Linux systems grep command is a powerful text search tool, it can use a regular expression search text, and print out the matching rows. grep stands for Global Regular Expression Print, represents the global regular expression version, its usage rights for all users.
1, Syntax Parameters
grep [options]
[Options] The main parameters:
-c: Only output count of matching lines.
-i: represents not case sensitive.
-h: do not display the file name when querying multiple files.
-l: only the output file name contains characters match the query multiple files.
-n: display matching lines and line number.
-s: do not display an error message does not exist or no match text.
-v: Displays all lines do not contain matching text, expressed reverse lookup.
--color = auto: You can find the key parts plus color display
2. Example:
1) Find the line that contains "png" of
[Linuxmi @ linux: ~ / linuxmi stray] $ grep -n 'png' linuxmi.py
2) Find does not include "png" row
[Linuxmi @ linux: ~ / linuxmi stray] $ grep -vn 'png' linuxmi.py
3) the query string is not na front of v
[Linuxmi @ linux: ~ / linuxmi 迷] $ grep -n '[^ v] na' linuxmi.py
4) Query front na not lowercase string
[Linuxmi @ linux: ~ / linuxmi 迷] $ grep -n '[^ az] na' linuxmi.py
5) ^ Matches start with a character. Query strings that begin with ba
[Linuxmi @ linux: ~ / linuxmi stray] $ grep -n '^ ba' linuxmi.py
6) [^] matches any character not included. The query string does not begin with a letter
[Linuxmi @ linux: ~ / linuxmi 迷] $ grep -n '^ [^ a-zA-Z]' linuxmi.py
7) $ matches the end of the line to a character. Query: end of the string
[Linuxmi @ linux: ~ / linuxmi stray] $ grep -n '. \ $' Linuxmi.py
// where the decimal point "." Has a special meaning, it is necessary to use the escape character "\" character has special meaning into ordinary characters
8). "" Matches any character other \ r \ outside n. It contains two characters between the query and l k row
[Linuxmi @ linux: ~ / linuxmi 迷] $ grep -n 'l..k' linuxmi.py
9) comprising continuous rows of the query e-letter
[Linuxmi @ linux: ~ / linuxmi stray] $ grep -n 'eee *' linuxmi.py
// "*" indicates a repeated zero or more of the preceding single character
10) l query to start with the end of the intermediate rows comprises at least one x-e of
[Linuxmi @ linux: ~ / linuxmi stray] $ grep -n 'lxx * e' linuxmi.py
11) Query line ends with the beginning of the l k, the middle of the dispensable characters
[Linuxmi @ linux: ~ / linuxmi 迷] $ grep -n 'l * k.' Linuxmi.py
12) {n} n times matching determination. Queries line contains two e's
[Linuxmi @ linux: ~ / linuxmi stray] $ grep -n 'e \ {2 \}' linuxmi.py
// "{}" is the need to use special characters "\" escape