Linux Learning Record-grep-egrep-is being expressed

Source: Internet
Author: User
Tags egrep

Grep

-I ignores case

--color Plus Color

-V shows rows that are not matched to

-O displays only the string that is matched to

Grep-o ROOT/ETC/PASSWD | Wc-l find how many root strings there are

-e Use extended regular expression egrep=grep-e

-A # grep-a 2 ' ^core ID '/proc/cpuinfo

-B # grep-b 2 ' ^core ID '/proc/cpuinfo

-C # grep-c 2 ' ^core ID '/proc/cpuinfo


Regular Expressions: Basic REGEXTP Basics

Extended regextp Extension

Regular expressions

. Represents any single character

* indicates that matches its preceding character any time

(Greedy mode)

AB, AAB, ACB, ADB, AMNB

A*b

A.*b

. * Any character of any length


\? Match the characters in front of it 1 or 0 times

\{m,n\} matches the preceding characters at least m times, up to N times

grep ' A\{1,3\}b ' test.txt

Ab

AaB

grep ' A.\{1,3\}b ' test.txt


Location anchoring:

^ The beginning of the anchor line, the character after the anchor must appear at the beginning of the line

grep ' ^r. T '/etc/passwd

$ Anchor Line end, the character before the anchor must appear at the end of the row

grep ' B. h$ '/etc/passwd

^$ Blank Line

grep ' ^$ '/etc/inittab

\< or \b Anchor Word, any subsequent character must appear as the first word

\> or \b Anchors the ending, any character before it must appear as the tail of the word

\<root\>


Group:

\ (\) to group content

\ (ab\) *

Back to reference

\1 refers to the first opening parenthesis and the corresponding closing parenthesis that contain the contents of the

grep ' \ (1..e\). *\1 ' Test.txt

grep ' \ ([0-9]\). *\1$ '/etc/inittab line appears with numbers that have the same end of data



Extended Regular Expressions: (and general regular expressions differ in many places without adding \)

-e using extended regular expressions

Character Matching:

.

[]

[^]

Number of matches:

*:

?:

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

? and + equals *

{M,n}


Group:

()

Or

|

C|cat C or Cat

(C|C) at cat or cat










Linux Learning Record-grep-egrep-is being expressed

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.