Linux-grep command (description of regular expressions and options)

Source: Internet
Author: User

1. grep is a powerful text search tool that uses regular expressions to match.

Format is: Gerp option ' script ' file

2, Regular expression:

(1) of which characters: +,. , (), |,{}.

In datum mode: The meaning of ordinary characters, the need for escape \.

In extended mode: Take special meaning.

(2) Character class:

. : Matches any one by one characters.

[]: Matches any one by one characters within [].

[-]: any one by one characters in the match range.

[^-]: matches any one by one characters except this range.

[--]: matches any one by one characters in both ranges.


(3) Quantity qualifier:

。 : matches the character before it o/1 times.

+: Matches the preceding character 1/multiple times.

*: matches the preceding character 0/multiple times.

{n}: matches the preceding character N times.

{N,}: matches the preceding character at least n times.

{, n}: matches the characters before it up to N times. I can't use it on my computer.

{n,m}: matches the preceding character between n~m times.



(4) Position qualifier:

^: Matches the beginning of the line.

$: Matches the end of the line.

\<: Match the position where the word is opened.

\>: A position that matches the end of a word.

\b: Matches the start or end of a word.

\b: Matches the position of the beginning or end of a word (the middle position of the word).


3, grep options:

(1)-e: Supports extension of regular expressions. grep defaults to the baseline mode.

(2)-r: Recursive search file.

(3)-O: Outputs only the results that match.

(4)-V: Flip match, that is, the output does not match.

(5)-C: Output matching to a total of a few.

(6)-L: Output matching files.

(7)-I: Ignores case matching.

(8)-N: The line number is also output.








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.