grep tool
The shell command line is convenient and the tools it supports are inseparable, and the grep tool is a search artifact that can search all the information in all the files in the entire Linux system.
The flexible use of grep is inseparable from regular expressions
A regular expression is a lookup and a string substitution operation, which is just a string with no length limitation, but generally a shorter table. Can be thought of as a lightweight, introduction, use and specific domain programming language.
The main use of the grep tool here
The grep tool is typically used to do two things, search for files and search for a specified string
grep Common Commands
-A Do not ignore binary data.
- b appears outside the row that conforms to the template style and displays the contents before the line.
-c< Displays the number of columns > or-< Displays the number of columns > in addition to displaying the column that conforms to the template style, and displays the contents before the column.
- c does not display matching information, only shows the number of matches to
-d< Action > When you specify that you want to find a directory rather than a file, you must use this parameter, otherwise the grep command returns information and stops the action.
-e< Template Style > Specify a string as the template style for finding the contents of a file.
- e uses the template style as an extended normal notation, which means that extended regular expressions can be used.
-I column character case difference.
- L lists file names that match the file contents to the specified template style.
- L lists file names for file contents that do not conform to the specified template style.
- n indicates the column number before displaying the column that conforms to the template style.
- Q does not display any information.
- s does not display an error message.
- v reverse lookup.
- y This parameter effect is the same as "-I".
- o to output only the portion of the file that matches
--color can be used to identify the matching color
grep regular expression has two modes, one is basic mode, the other is extend mode (that is, add-e), do not add the basic mode of E? {}+ () | is the literal meaning of itself, not the meaning of the regular, if you want to use the regular meaning to use \ Translation, while the-e mode is the opposite
For example, we touch a file: The contents are as follows, the number is 1-100,
Hello-world86hello-world87hello-world88hello-world89hello-world90hello-world91hello-world92
Now we're going to find those lines with a mantissa of 9, and label them with color.
[Email protected] grep]$ grep-e--color '. 9$ ' file Hello-world9hello-world19hello-world29hello-world39hello-world49hello-world59hello-world69hello-world79hello-world89hello -world99
That way, if we only ask for the number of matches to be displayed, then the-C option
Grep-ec--color '. 9$ ' file
It can be seen that grep's format is probably this form, the main or the subsequent lookup method associated with the regular expression
Summary: grep is a powerful find tool that can be easily used when searching quickly
This article is from the "Traces" blog, be sure to keep this source http://wpfbcr.blog.51cto.com/10696766/1792832
Shell Script--grep Tool