Linux--grep and regular Expressions (II.)

Source: Internet
Author: User

There are two types of regular expressions:

Basic REGEXP: Basics

Extended REGEXP: Extended

Basic Regular Expressions:

. : Any single character

[]: A single character in the specified range

[^]: Specify a single character outside the range

Number of matches:

*: The characters in front of it any time

\?:0 or 1 times

\{m,n\}: At least m times, up to N times

. *: Any character of any length

Anchoring:

^: Anchor at the beginning of the line

$: End of line anchoring

\<: Anchor Word first

\>: Anchor ending

\ (\): Grouping

\1,\2,\3,...

grep: A command that filters text using patterns defined by a basic regular expression

-I: Case insensitive

-V: Reverse match

-O: Show only the matching string

--color: Matching to the highlighted display

-E: Using extended regular expressions

-A #: When a row is matched to a pattern specified by grep, the line is displayed, followed by

-B #: Ditto, not only the matching line shows, the front also shows

-C #: Ditto, not only the matching line shows, the upper and lower # lines are also displayed

To extend the regular expression:

Character Matching:

. : Matches a single character

[]: A single character in the specified range

[^]: Specify a single character outside the range

Number of matches:

*; its preceding character any time

? : Its former character 0 or 1 times

+: Match the characters in front of it at least once

{M,n}

Location anchoring:

^

$

\<

\>

Group:

(): Group

\1,\2,\3,...

Or

| : OR

C|car:c or Cat

GREP-E = Egrep

Match white space characters at least once

# grep-e ' ^[[:space:]]+ '/etc/passwd

Find the number between 1-255 in the/boot/grub/grub.conf file;

# egrep ' \< ([1-9] | [1-9] [0-9] | 1 [0-9] [0-9] | 2 [0-4] [0-9] | [0-5]) \> '/boot/grub/grub.conf

IPv4:

Five categories:

A:1-127

b:128-191

c:192-223

D

E

Match IP:

# \< ([1-9]|[ 1-9][0-9]|1[0-9]{2}|2[01][0-9]|22[0-3]) \> (\.\< ([0-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4] \>) {2}\.\< ([1-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4]) \>

Grep,egrep

Fgrep: Regular expressions are not supported

Linux--grep and regular Expressions (II.)

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.