1. Background
When it comes to shell programming, we have to mention regular expressions, the "old guy" that can look like a new programming language, and let a lot of our just-in-the-box programmers love and hate because they can actually write powerful features in the shortest sentences Hate is because its syntax doesn't seem like any of the high-level programming languages we were in contact with. Let's start with the main introduction to the regular
2. Regular classification
-
Basic Regular: Out of the early, grep is generally the default is the basic regular
Extended Regular: Extended to basic, more escape characters are supported by default
3. Basic syntax
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/83/5C/wKiom1dxLYDTb0hVAAA3aNgNSIg918.png "title=" Character class. png "alt=" Wkiom1dxlydtb0hvaaa3angnsig918.png "/>
4. Quantity limit Symbol
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/83/5B/wKioL1dxLYmTPtF1AABgCiTZlUs616.png "title=" The number qualifier. png "alt=" Wkiol1dxlymtptf1aabgcitzlus616.png "/>
5. Position Qualifier
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/83/5B/wKioL1dxLeeAEl95AAAyclQ3WBY204.png "title=" Position limit symbol. png "alt=" Wkiol1dxleeael95aaayclq3wby204.png "/>
6. Other special characters
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/83/5C/wKiom1dxLh2yX1m1AAA2NV4Skpo871.png "title=" Other special characters. png "alt=" Wkiom1dxlh2yx1m1aaa2nv4skpo871.png "/>
grep
1. Role
The grep command in a Linux system is a powerful text search tool that uses regular expressions to search for text and print matching lines. The grep full name is global Regular expression Print, which represents the globally regular expression version, and its use rights are for all users.
The grep family includes grep, Egrep, and Fgrep. Egrep and Fgrep commands are only a small difference from grep. Egrep is the extension of grep, which supports more re metacharacters, and fgrep is fixed grep or fast grep, which regards all the letters as words, that is, the metacharacters in the regular expression represents the literal meaning back to itself, no longer special. Linux uses the GNU version of grep. It is more powerful and can use the Egrep and FGREP functions with the-G,-e,-f command line options.
2. Parameters
grep [Options]
Main parameters: Linux under grep--help can be viewed
-C: Output only the count of matching rows
-I: Case insensitive
-H: Do not display file names when querying multiple files
-L: Only file names with matching characters are output when querying multiple files
-N: Display matching row-level line numbers
-S: Do not display error messages for nonexistent or no matching files
-V: Displays all lines that do not contain matching text
--color=auto: You can add a color display to the Found keywords section
actual operation:
1, the known file test.txt content is [Test][liyao][sea], please give the print test.txt content, does not contain sea command for string
[ Assuming this directory file is present under/data/ ]
Method One: grep-v "sea"/data/test.txt
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/83/5C/wKiom1dxMG2gzfHAAAA-pVwqikE192.png "title=" Security-method one. png "alt=" Wkiom1dxmg2gzfhaaaa-pvwqike192.png "/>
method One: Cat/data/test.txt | grep-v "Sea"
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/83/5C/wKiom1dxMP2SZXZEAAA5aKJ8X40331.png "title=" Security-Method two. png "alt=" wkiom1dxmp2szxzeaaa5akj8x40331.png "/> Contrast two methods, method two is slower than method one, but professional.
This article is from the "Sea" blog, be sure to keep this source http://lisea.blog.51cto.com/5491873/1793447
Linux----->shell Advanced Programming----grep application