What is a regular expression:
The regular expression is the method that handles the string, he is the behavior unit to carry on the string processing behavior, the regular expression through some special symbol's auxiliary, may let the user easily achieves the search, the deletion, replaces a certain string's handler, actually like quite with adds the position qualifier, the quantity qualifier, Character to set the range reduction match.
2.grep Tools:
First, grep is a lookup tool, and then a regular expression completes the search for the string.
There are 3 qualifiers:
The first is the character qualifier:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/83/3B/wKioL1ds-b7znjbDAAC02XtIx6o155.png "style=" float: none; "title=" QQ picture 20160624171053.png "alt=" Wkiol1ds-b7znjbdaac02xtix6o155.png "/>
Quantity qualifier:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/83/3B/wKiom1ds-b6AqpxkAADuk6KOFII285.png "style=" float: none; "title=" QQ picture 20160624171109.png "alt=" Wkiom1ds-b6aqpxkaaduk6kofii285.png "/>
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/83/3B/wKiom1ds-b-y8zbmAABOzC1hDBE800.png "style=" float: none; "title=" QQ picture 20160624171127.png "alt=" Wkiom1ds-b-y8zbmaabozc1hdbe800.png "/>
Position qualifier:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/83/3B/wKioL1ds-cDgmsXrAACyIbvf5CM604.png "style=" float: none; "title=" QQ picture 20160624171138.png "alt=" Wkiol1ds-cdgmsxraacyibvf5cm604.png "/>
Other qualifiers:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/83/3B/wKioL1ds-cHx_dW5AACi_VlN2vI614.png "style=" float: none; "title=" QQ picture 20160624171147.png "alt=" Wkiol1ds-chx_dw5aaci_vln2vi614.png "/>
is the extended specification for grep regular expressions, and the basic specification also has these syntaxes, just characters? +{}| () shall
interpreted as ordinary characters, to indicate that the above special meaning needs to be added \ escaped. If you use grep instead of egrep and do not add-E
parameter, the regular expression should be written in accordance with the basic specification. (Be sure to pay attention to!!!!! )
Let's take a look at the various options for grep, and combine the various qualifiers above to use the following:
The common grep options are:
-C outputs only the count of matching rows.
- I is case-insensitive (only for single-character).
-H does not display a file name when querying multiple files.
-L Only output file names that contain matching characters 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.
One by one:
First we enter the command under Terminal: Count=0;while [$count-le];d o echo "Hello abc $count" >>file;let count++;d One
Create a 100-line file:
-C: outputs only the count of matching rows.
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/83/3C/wKiom1dtAKryC4aGAAA9yAOnhHU585.png "title=" QQ picture 20160624174252.png "alt=" Wkiom1dtakryc4agaaa9yaonhhu585.png "/>
-------------------------------------------------------------------------------------------
-I: Case insensitive (only for single-character).
Before using this, we used the SED tool to convert the file files: the SED tool will write blog posts later.
Sed-i/he/s/he/he/g File
That means we're converting every line of he into he.
Then we use grep-i;
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/83/3C/wKiom1dtAbvRKcM8AAAoHxYdb5k625.png "title=" QQ picture 20160624174723.png "alt=" Wkiom1dtabvrkcm8aaaohxydb5k625.png "/>
-------------------------------------------------------------------------------------------
-H does not display a file name when querying multiple files.
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/83/3B/wKioL1dtA9iQJRuqAAB7SkIefD8511.png "style=" float: none; "title=" QQ picture 20160624175232.png "alt=" Wkiol1dta9iqjruqaab7skiefd8511.png "/>
-------------------------------------------------------------------------------------------
-N Displays matching lines and line numbers.
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/83/3C/wKiom1dtA9mBmze9AABxt1Ikr98553.png "style=" float: none; "title=" QQ picture 20160624175317.png "alt=" Wkiom1dta9mbmze9aabxt1ikr98553.png "/>
-------------------------------------------------------------------------------------------
-S does not display error messages that do not exist or have no matching text.
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/83/3C/wKiom1dtA9nCU_diAAAk4vtyya8530.png "style=" float: none; "title=" QQ picture 20160624175415.png "alt=" Wkiom1dta9ncu_diaaak4vtyya8530.png "/>
-------------------------------------------------------------------------------------------
-V Displays all lines that do not contain matching text.
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/83/3B/wKioL1dtA9qD89StAACVXvAnKWA158.png "style=" float: none; "title=" QQ picture 20160624175521.png "alt=" Wkiol1dta9qd89staacvxvankwa158.png "/>
-------------------------------------------------------------------------------------------
-L Only output file names that contain matching characters when querying multiple files.
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/83/3B/wKioL1dtBEiTgQrpAAAkIbxuXXk979.png "title=" QQ picture 20160624175819.png "alt=" Wkiol1dtbeitgqrpaaakibxuxxk979.png "/>
This is what is commonly used =. =
This article is from the "egg-left" blog, please be sure to keep this source http://memory73.blog.51cto.com/10530560/1792687
Linux: Regular expressions and: grep tools