Linux_grep and regular expressions

Source: Internet
Author: User

linux-basic-grep and regular expressions

Text Lookup command:

Grep,egrep,fgerp


grep: Searches text based on patterns and displays lines of text that conform to the pattern

Pattern: The matching criteria for the combination of meta-characters of the expression wildcards regular the text character


grep [option] PATTERN [FILE ...]

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/6D/wKioL1Xj7UDhoVyRAACOcw3ADHE244.jpg "title=" 1.png " alt= "Wkiol1xj7udhovyraacocw3adhe244.jpg"/>

To find the contents of a file that contains the root string


Parameters for grep

-I: Indicates ignoring case

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/71/wKiom1Xj6zyy6jqBAABm8kRafNg389.jpg "title=" 2.png " alt= "Wkiom1xj6zyy6jqbaabm8krafng389.jpg"/>

The case of the H letter is ignored in the


--color: The matching option is highlighted with highlighting

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/6D/wKioL1Xj7XGiFitWAABTXlpCTfM515.jpg "title=" 3.png " alt= "Wkiol1xj7xgifitwaabtxlpctfm515.jpg"/>


-V: Reverse lookup, rows that are matched to are not displayed, rows that do not match are displayed

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/71/wKiom1Xj63rAZQpQAACEGSi4sQQ939.jpg "title=" 4.png " alt= "Wkiom1xj63razqpqaacegsi4sqq939.jpg"/>


-O: Displays only the strings that are matched, one row for each string

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/6D/wKioL1Xj7a7ixbMnAAAyIQW7qGk278.jpg "title=" 5.png " alt= "Wkiol1xj7a7ixbmnaaayiqw7qgk278.jpg"/>


-W: Absolute match

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/6D/wKioL1Xj7iXjcFiNAABvnuiqbNE955.jpg "title=" 100. PNG "alt=" wkiol1xj7ixjcfinaabvnuiqbne955.jpg "/>

@@@@@@@@@@@

The following are the definitions in the wildcard characters:

*: Any character of any length

? : Any single character

[]: Within the specified range

[^]: outside the specified range

These definitions have been changed in the meta-character, note the distinction between

@@@@@@@@@@@


Regular Expressions: Regular expression


Metacharacters

.: Any single character

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/6D/wKioL1Xj7fPANffWAABumn3tNUk277.jpg "title=" 6.1. PNG "alt=" wkiol1xj7fpanffwaabumn3tnuk277.jpg "/>

Represents any two single characters between R and T, and all r/ft on the way are matched.

[]: matches any single character within the specified range

[^]: matches any single character outside the specified range

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/71/wKiom1Xj7BzDle7ZAABHZ8VxKzI874.jpg "title=" 7.jpg " alt= "Wkiom1xj7bzdle7zaabhz8vxkzi874.jpg"/>

The above character sets correspond to each other: numeric lowercase letters, uppercase punctuation, whitespace characters, all letters, all numbers and characters, these references need to be used in addition [], two []

Number of characters

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/6D/wKioL1Xj7lmAN1lwAAAW30Tnrvo806.jpg "title=" 8.jpg " Style= "Float:none;" alt= "wkiol1xj7lman1lwaaaw30tnrvo806.jpg"/>

*: Match the characters in front of it Fuzhin Italian Times

For example, a*b means that there is an arbitrary number of a in front of B ( instead of A and B can have any character, A and B can have any character is a wildcard representation, not a meta-character representation ), that is, can match the preceding 0 a, 1 a,ab , the first 2 A,aab, and so on, so in addition to the number one and the last three, the other can be matched to.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/71/wKiom1Xj7Dqyo_ReAAAvWfI35y8982.jpg "title=" 9.png " Style= "Float:none;" alt= "wkiom1xj7dqyo_reaaavwfi35y8982.jpg"/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/6D/wKioL1Xj7lngc8UpAAA2uSORtDs577.jpg "title=" 10.png "Style=" Float:none; "alt=" wkiol1xj7lngc8upaaa2usortds577.jpg "/>650" this.width=650; "src=" http://s3.51cto.com/ Wyfs02/m00/72/6d/wkiol1xj7lnxhs4paaa73zq-uom665.jpg "title=" 11.png "style=" Float:none; "alt=" Wkiol1xj7lnxhs4paaa73zq-uom665.jpg "/>

All red is the matching success.


. *: denotes arbitrary length of any character, greedy mode, as long as possible to match

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/71/wKiom1Xj7Kewebq6AAAozLx8awQ722.jpg "style=" float: none; "title=" 12.jpg "alt=" Wkiom1xj7kewebq6aaaozlx8awq722.jpg "/>

The a.*b means a begins, B ends, and any character in the middle

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/6D/wKioL1Xj7sbx4QAiAABD_Un1dIs586.jpg "style=" float: none; "title=" 12.png "alt=" Wkiol1xj7sbx4qaiaabd_un1dis586.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/6D/wKioL1Xj7wPS2Z5tAAA5k5uJqFs029.jpg "style=" float: none; "title=" 13.png "alt=" Wkiol1xj7wps2z5taaa5k5ujqfs029.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/6D/wKioL1Xj7wPRrmmaAAA10MpDN5E049.jpg "style=" float: none; "title=" 14.png "alt=" Wkiol1xj7wprrmmaaaa10mpdn5e049.jpg "/>

Unable to match to SSADDB


It can be understood that the second and subsequent values in front are dead, must exist, and that the first character in front can be any number, which can be 0.

\?: Match its preceding character 1 or 0 times

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/71/wKiom1Xj7OSg-zO4AAAu8d9TsLU451.jpg "title=" 15.png "Style=" Float:none; "alt=" wkiom1xj7osg-zo4aaau8d9tslu451.jpg "/>

AaB cannot be fully matched


\{m,n\}: Matches its preceding character at least m times, more than n times

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/71/wKiom1Xj7Qai1Tv2AAA-fbZ0aoo587.jpg "style=" float: none; "title=" 16.png "alt=" Wkiom1xj7qai1tv2aaa-fbz0aoo587.jpg "/>

\{1,\}: Indicates at least once, up to No limit

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/6D/wKioL1Xj7yXju-ABAAAyykj9R2s186.jpg "title=" 17.png "Style=" Float:none; "alt=" wkiol1xj7yxju-abaaayykj9r2s186.jpg "/>

Indicates that a minimum of 1 to 3 characters can occur between A and B


Location anchoring:

^: Anchor the beginning of the line, any content after this character must appear at the beginning of the line

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/71/wKiom1Xj7QfhhxvrAACfJsdl_JI670.jpg "title=" 18.png "Style=" Float:none; "alt=" wkiom1xj7qfhhxvraacfjsdl_ji670.jpg "/>


$: Anchor Line end. Any content preceding this character must appear at the end of the line

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/6D/wKioL1Xj7yWh6--qAAB2LIMHnx4400.jpg "title=" 19.png "Style=" Float:none; "alt=" wkiol1xj7ywh6--qaab2limhnx4400.jpg "/>


^$: Blank Line

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/71/wKiom1Xj7QeCOcmIAAAkI8EWw7w770.jpg "title=" 20.png "Style=" Float:none; "alt=" wkiom1xj7qecocmiaaaki8eww7w770.jpg "/>


^#$: Represents a row that matches a line that starts with #, with empty contents in the middle

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/6E/wKioL1Xj76Pibc9eAACXRsMUjzU597.jpg "style=" float: none; "title=" 21.png "alt=" Wkiol1xj76pibc9eaacxrsmujzu597.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/71/wKiom1Xj7YXB1xXwAABOqsRxEa8379.jpg "style=" float: none; "title=" 22.jpg "alt=" Wkiom1xj7yxb1xxwaaboqsrxea8379.jpg "/>


Represents the content that matches a number ending with a white space character


\< or \b: Anchor word, any character following it must appear as the first word

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/6E/wKioL1Xj76OiEU4xAAB3xBhZMKE966.jpg "title=" 23.png "Style=" Float:none; "alt=" wkiol1xj76oieu4xaab3xbhzmke966.jpg "/>


\> or \b: anchors the ending, any character in front of which must appear as the tail of the word

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/72/71/wKiom1Xj7YXjb0njAABuolUSoxE102.jpg "style=" float: none; "title=" 24.png "alt=" Wkiom1xj7yxjb0njaabuolusoxe102.jpg "/>

Not counted as part of the tail of the word


\<root\>: Exact Match root word

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/72/6E/wKioL1Xj76PyYnFNAAAzzT2M6gM593.jpg "title=" 25.png "Style=" Float:none; "alt=" wkiol1xj76pyynfnaaazzt2m6gm593.jpg "/>


Group:

\(\)

\ (ab\) *: This means AB can appear 0 or any time, back reference

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/6E/wKioL1Xj8GrQqNReAABBQTauFIA669.jpg "style=" float: none; "title=" 26.jpg "alt=" Wkiol1xj8grqqnreaabbqtaufia669.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/72/71/wKiom1Xj7kzzeMXgAACNUV6sSWA126.jpg "style=" float: none; "title=" 27.jpg "alt=" Wkiom1xj7kzzemxgaacnuv6sswa126.jpg "/>






This article is from the "It_landscape" blog, make sure to keep this source http://huangyisan.blog.51cto.com/6925110/1690105

Linux_grep and regular expressions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.