Regular expression grep egrep fgrep in Linux

Source: Internet
Author: User
Tags egrep

Regular Expressions: REGEXP Reguler expression, which uses metacharacters and other strings to describe and match a series of strings that conform to a certain syntactic rule . The default is to match as long as possible (greedy mode).

Metacharacters

.: Matches any single character (in file name wildcard?). Represents any single character)

[]: matches a single character within a specified range

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

[: Space:]: white space character

[:p Untt:]: All punctuation

[: Upper:]: All uppercase letters

[: Lower:]: All lowercase letters

[: Alpha:]: All uppercase and lowercase letters

[:d Igit:]: All numbers

[: Alnum:]: All numbers and uppercase and lowercase letters

Character Count matches:

*: matches any number of characters in the preceding character (the file name in the wildcard * denotes any character of any length)

. *: Any character of any length

\?: matches its first character once or 0 times, can be used without

\{\}:\{m,n\} matches its first character at least m times, up to N times

Eg:\{1,\} at least 1 times; \{0,3\} up to 3 times

Location anchoring:

^: Anchor the beginning of the line, after which the character must appear at the beginning

$: Anchor Line end, whose preceding character must appear at the end of the row

^$: Blank Line

\<: The following character must appear as the word header and can be replaced with \b

\>: The first character must appear as the tail of the word, and can be replaced with \b

eg:\<root\>==\broot\b

Group: \ (\)

Eg:\ (a,b\) *:ab appears any time

The main function of the parentheses is not to make the contents of the content be regarded as a whole, but to facilitate the subsequent content reference (back reference)

Eg:\1: Call the first opening parenthesis and its corresponding closing parenthesis to include the contents

\ n: Invokes the preceding nth opening parenthesis and its corresponding closing parenthesis for what is included


Regular expressions: Divided into basic regular expressions and extended regular expressions

To extend the regular expression:

Character Matching:

., [],[^] is the same as the basic regular expression


Number of Matches

*,? : The same as the basic regular expression? Before you need to add \

+: Its pre-character at least once = = in basic regular expression \ (1,\)

{M,n}: At least m times up to N times, less than the base regular expression curly braces


Anchor character:

\< \> ^ $ \b As with basic regular expressions


Group:

(): No need to add \ support \1,\2,\3,...


Or:

|:or or

Eg:a|b A or B

Eg:c|cat==c or cat (not cat or cat)


grep: Searches for text according to the pattern and displays lines of text that conform to the pattern. a command that uses a basic regular expression and its defined pattern to filter text.

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

-I: Ignore case

--color: Matched to the character plus color display

-O: displays only the string that is matched to

-V: reverse lookup, displaying rows of content that are not matched by a pattern

-E: Using extended regular expressions

-A N: Displays the line that is matched to and the next n rows

-B N: displays the line to which it was matched and its first n rows

-C N: displays the line to which it is matched and the N rows before and after it

Egrep: a command that uses extended regular expressions and its defined patterns to filter text.

Egrep=grep-e


Fgrep:fast grep Quick Find characters do not support regular expressions and are searched by string.


Regular expression grep egrep fgrep in Linux

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.