Five. Regular expression grep, Egrep, Fgrep

Source: Internet
Author: User
Tags uppercase letter egrep

Grep,egrep,fgrep:print lines matching a pattern

1.grep:

grep [options] PATTERN FILE ...

Pattern is made up of meta characters and ordinary characters

-I:--ignore-case, ignoring case

-O:--only-matching, displays only the characters that are matched, and two is not the whole line

-N:--line-number, outputs the line number of the matched row

-V:--invert-match, showing all rows except matching rows

-e:--extended-regexp, Egrep

-F:--fixed-strings, Fgrep

-P:--per-regexp

-A num:--after-context, which displays NUM lines after matching lines

-B Num:--before-context, display matching line strong NUM line

-C num:--context, displays the front and rear NUM lines of the matching line

Metacharacters

Match characters:

. : Matches any single character

[],[^]: matches the specified single character

[0-9], [[:d Igit:]]: matches a single number

[[: Alpha:]]: Matches a single large, lowercase letter

[[: Lower:]]: matches a single lowercase letter

[[: Upper:]]: Matches a single uppercase letter

[[: Alnum:]]: Matches a single number or letter

[[: Bank:]]: Matches a single white space character

[[:p UNCT:]]: Match punctuation

[[: Contrl:]]: match when control character

[[: Xdigit:]]: Matches a single 16 binary number

Number of matches: used to specify the number of occurrences of the preceding character

*: Any number of times, including 0

\+: At least once

\? : 0 or 1 times, the preceding characters can have, can be no

\{m\}, \{0,n\}, \{m,n\}, \{m,\}: Refers to M times, up to n times, m-n times, minimum m times

. *: Any length, any character

Location anchoring:

^: Anchor at the beginning of the line, mode left

$: End of line anchoring, mode right

\<: First anchor, Word pattern left, Word refers to a string of numbers and letters

\>: Ending anchor, Word right

^pattern$, matches the entire line only the specified pattern

^$: Blank Line

^[[:blank:]]$: No visible characters for entire line

\<word\>: Match Whole word

Group

\ (\) Enclose any character in parentheses to make a whole match.

Back reference: Apply the contents of the preceding grouping brackets, not the schema itself, \1,\2 ...

\ (th\). *\1: Matches what the first parenthesis matches

    

2. Egrep: Equivalent to GREP-E

egrep [options] PATTERN FILE ...

Pattern is made up of meta characters and ordinary characters

-I:--ignore-case, ignoring case

-O:--only-matching, displays only the characters that are matched, and two is not the whole line

-N:--line-number, outputs the line number of the matched row

-V:--invert-match, showing all rows except matching rows

-A num:--after-context, which displays NUM lines after matching lines

-B Num:--before-context, display matching line strong NUM line

-C num:--context, displays the front and rear NUM lines of the matching line

Pattern is made up of meta characters and ordinary characters

Metacharacters

Match characters:

. : Matches any single character

[],[^]: matches the specified single character

[0-9], [[:d Igit:]]: matches a single number

[[: Alpha:]]: Matches a single large, lowercase letter

[[: Lower:]]: matches a single lowercase letter

[[: Upper:]]: Matches a single uppercase letter

[[: Alnum:]]: Matches a single number or letter

[[: Bank:]]: Matches a single white space character

[[:p UNCT:]]: Match punctuation

[[: Contrl:]]: match when control character

[[: Xdigit:]]: Matches a single 16 binary number

Number of matches: used to specify the number of occurrences of the preceding character

*: Any number of times, including 0

+: At least once

? : 0 or 1 times, the preceding characters can have, can be no

{m}, {0,n}, {m,n}, {m,}: Refers to M times, up to n times, m-n times, minimum m times

. *: Any length, any character

Location anchoring:

^: Anchor at the beginning of the line, mode left

$: End of line anchoring, mode right

\<: First anchor, Word pattern left, Word refers to a string of numbers and letters

\>: Ending anchor, Word right

^pattern$, matches the entire line only the specified pattern

^$: Blank Line

^[[:blank:]]$: No visible characters for entire line

\<word\>: Match Whole word

Group

() enclose any character in parentheses to make a whole match.

Back reference: Apply the contents of the preceding grouping brackets, not the schema itself, \1,\2 ...

(TH). *\1: Matches what the first parenthesis matches

3.fgrep: Regular expressions are not supported, matching only the specified string

Fgrep [optings] patern File ...

Five. Regular expression grep, Egrep, Fgrep

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.