Linux Text Search tool grep

Source: Internet
Author: User

Linux Text Search tool grep

grep function: Search for text based on patterns and display lines of text that conform to the pattern

Pattern: The matching condition of the wildcards regular of the expression with the text character

1 wildcard characters:

*: Any character of any length

?: any single character

[]: matches any single character within the specified range

[^]: contrary to []

2 Regular Expressions:

Metacharacters

.: Matches any single character

*: Number of matches (working in greedy mode, as long as possible),

Match any of its preceding characters

. *: Any character of any length

\?: Match its preceding character 1 or 0 times

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

\{1,\}: Match its preceding characters 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, any content in front of this character must appear at the end of the row

^$: Blank Line

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

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

Group

\ (string\): string as a set of characters, a whole, for a back reference

Back to reference

\1: Refers to the first opening parenthesis and all the contents of the corresponding closing parenthesis

\2

\3

grep Basic usage:

grep [OPTIONS] PATTERN [FILE ...]

OPTIONS

-I: Ignore case

--color: descriptor color of the searched word

-V: Show rows that are not matched by the pattern

-O: Displays only the string that is matched to

-A #: Indicates the line to which grep matches and the # line after it

-B #: Indicates the line to which grep matches and the previous # line

-C #: Indicates the line to which grep matches and the # lines before and after

-e: Match extended regular expression

Extended Regular Expression Egrep

Number of Matches

+: Match the characters in front of it at least 1 times

Group

(): In parentheses as a whole



This article is from the "surgery industry has specialized" blog, please be sure to keep this source http://fuvip.blog.51cto.com/9276123/1981118

Linux Text Search tool 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.