Linux command (one)--grep command and regular expression

Source: Internet
Author: User

grep command: Print lines matching a pattern

"Feature" uses the grep command to find a matching string in the contents of a file, also known as a filter, which of course supports the use of regular expressions in combination.

Syntax

grep [Options][pattern] filename

"Common Options"

-I: Indicates ignoring the case display of-N: Output line number-O: Indicates that only the display is matched to the pattern itself-V: Indicates that the display is reversed, the matching is not displayed, and the display is not matched to the--color=auto: the color of the matched content is displayed

"Instance 1" default shaded display

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7F/4B/wKiom1cY5H6Czfx4AAAoTeGD9zw597.png "title=" 1.png " alt= "Wkiom1cy5h6czfx4aaaotegd9zw597.png"/>

"Instance 2"-I option is case insensitive

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7F/4B/wKiom1cY5kvjDl30AABJ_Jo204w023.png "title=" 3.png " alt= "Wkiom1cy5kvjdl30aabj_jo204w023.png"/>

Instance 3 inverse and display line numbers

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7F/4C/wKiom1cY5ufQ8wdwAABJQcCUxFs900.png "title=" 4.png " alt= "Wkiom1cy5ufq8wdwaabjqccuxfs900.png"/>

"Instance 4" shows only the match to the pattern itself

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7F/4A/wKioL1cY8MvQM__0AAAclTbSV18577.png "title=" 1.png " alt= "Wkiol1cy8mvqm__0aaacltbsv18577.png"/>


Regular expressions: In a Linux system, the shell has specific special symbols to implement the specified string in the matched text, which can be implemented using the regular expression matching pattern, similar to the Glob wildcard, when many complexities are difficult to write or match a specific location [range].

There are a wide range of expressions used in Linux systems, and there are several common tools for using regular expressions:

The grep tool Family (GREP,GREP,FGREP) used to match lines of text is used to change the input stream of the SED flow editor (Stram Editor) for handling string language Gawk,python,perl such as file Viewer programs, or pager, more, Less text editor vim

Regular representations are divided into basic regular expressions and extended regular expressions

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7F/4A/wKioL1cY-aaRusaiAACtxh6RIfY108.png "title=" 2.png " alt= "Wkiol1cy-aarusaiaactxh6rify108.png"/>

Note: If there are more than one () in the group, the latter reference points before or after, or (()) from the outside to the inside of the \1\2


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7F/4C/wKiom1cZAKaCfB4jAABHFlE9wZY305.png "title=" 4.png " alt= "Wkiom1czakacfb4jaabhfle9wzy305.png"/>


"Instance 1" mode "^1", which represents the line that matches the first behavior 1, anchors the beginning of the row

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7F/4A/wKioL1cZA-2Qu_6hAAAo-LrStfU455.png "title=" 5.png " alt= "Wkiol1cza-2qu_6haaao-lrstfu455.png"/>

"Instance 2" mode "$", which represents lines that match end-of-line characters, anchors line endings

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7F/4A/wKioL1cZBMHRti0BAAAv7R3LHbQ298.png "title=" 6.png " alt= "Wkiol1czbmhrti0baaav7r3lhbq298.png"/>

"Instance 3" mode {m}, which matches the preceding character 1m matches,

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/7F/4C/wKiom1cZBObTdrK2AAAtKT_pZIo029.png "title=" 7.png " alt= "Wkiom1czbobtdrk2aaatkt_pzio029.png"/>

"Instance 4" matches at least once, up to n times

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7F/4C/wKiom1cZBeDCjhyAAAAqtiNJbkw357.png "title=" 8.png " alt= "Wkiom1czbedcjhyaaaaqtinjbkw357.png"/>

"Instance 5" matches the preceding character at least m times, up to n matches

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7F/4C/wKiom1cZBu3BoFlJAAArFJzWz5A858.png "title=" 12.png "alt=" Wkiom1czbu3bofljaaarfjzwz5a858.png "/>

"Instance 6" private Character set


650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7F/4B/wKioL1cZKG_ytVRsAABZf3Vz1Fs195.png "title=" 123. PNG "alt=" Wkiol1czkg_ytvrsaabzf3vz1fs195.png "/>


This article is from the "Perthon" blog, make sure to keep this source http://perthon.blog.51cto.com/10484057/1766513

Linux command (one)--grep command and regular expression

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.