grep
1. Role
The grep command allows you to specify a file to search for specific content and to output the standard rows containing the content. The grep full name is global Regular expression Print, which represents the globally regular expression version, and its use rights are for all users.
2. Format
grep [Options]
3. Main parameters
[Options] main parameters:
-C: Outputs only the count of matching rows.
- I: Case insensitive (only for single-character).
-H: The file name is not displayed when querying multiple files.
-L: Only file names that contain matching characters are output when querying multiple files.
-N: Displays matching lines and line numbers.
-S: does not display error messages that do not exist or have no matching text.
-V: Displays all lines that do not contain matching text.
pattern Regular Expression main parameters:
\: Ignores the original meaning of special characters in regular expressions.
^: Matches the start line of the regular expression.
$: Matches the end line of the regular expression.
\: The end of the line to match the regular expression.
[]: a single character, such as [a], a meets the requirements.
[-]: range, such as [A-z], i.e. A, B, C to Z all meet the requirements.
. : all the individual characters.
*: There are characters, the length can be 0.
is
the expression is a very important concept in the Linux/unix system. A regular expression (also known as "regex" or "regexp") is a pattern that can describe a class of strings
(Pattern). If a string can be described with a regular expression, we say that the character matches the regular expression (match). This and DOS users can use wildcard characters
"*" stands for any character similar. On Linux systems, regular expressions are often used to find patterns in text, and to perform "search-and-replace" operations and other functions on text.
4. Application examples
Check
Consulting The DNS service is one of the daily tasks, which means maintaining a large number of IP addresses that cover different networks. Sometimes there are more than 2000 IP addresses. If you want to see the NNN.NNN network address, but forget
the remainder of the second part is only known to have two periods, such as nnn nn ... To extract all of the nnn.nnn IP addresses, use the [0-9]\{3
\}\. [0-0\{3\}\. The meaning is that any number appears 3 times, followed by a period, followed by any number 3 times, followed by a period.
$grep ' [0-9]\{3 \}\. [0-0\{3\}\ ' Ipfile
to add, the grep family also includes Fgrep and Egrep. Fgrep is fix grep, which allows to find strings instead of a pattern; Egrep is an extended grep that supports both basic and extended regular expressions, but does not support the application of \q mode scope and some of the more canonical patterns corresponding to it.
This article is from the "--" blog, please be sure to keep this source http://57388.blog.51cto.com/47388/1544716
linux-File Processing command-grep