The Linux base command grep

Source: Internet
Author: User

grep :

Searches for text based on pattern (mode) and displays lines of text that conform to the pattern, without modifying the original file.

Usage: grep [options] ' pattern '/file #也可以利用管道进行匹配

-I ignore ignoring case

--colour the matched string with a color.

-V reverse lookup, showing rows that do not match pattern

-O displays only strings that are matched by the pattern

Regular Expressions REGular expressionWork in greedy mode and try to match as much as possible. Meta characters:

. : Matches any single character

[]: matches any single character within the range

[:d Igit:] number [: lower:] lowercase letter [: Upper:] Uppercase [:p UNCT:] punctuation [: space:] space [: Alpha:] All characters [: Alnum:] All letters and numbers

Usage: [[:d Igit:]]

[^]: matches any single character outside the range

number of matching characters:

*: matches the preceding character any time (including 0 times)

. *: Any character of any length

\? : matches the preceding character 1 or 0 times, generally add \

\{m,n\}: Matches the preceding character at least m times, up to N times.

\{1,\}: Matches the preceding character at least 1 times

Location Anchoring:

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

$: Anchor Line End

^$: Blank Line

\b or \<: Any character following this character must appear as the header of the word

\b or \>: Any character preceding this character must appear as the tail of the word

Grouping

\ (\) usage difference: ab* \ (ab\) *

Can back reference: he love his lover

She like her liker

He like his lover

\1: Represents the invocation of the first opening parenthesis and all the contents of the corresponding closing parenthesis.

\2: ...

The Linux base command grep

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.