LINUX common Commands (iv)

Source: Internet
Author: User

8. using regular Expressions with grep

Regular expression: He uses a string to describe, match some of the syntax rules of a string, so that these rules of the syntax of the string, the corresponding processing.

Common support for regular expression tools is as follows:

Grep command family for matching lines of text

The Sed Flow Editor is used to change the input stream

Awk for working with string languages

More or less file viewer program

Ed,vi,vim text compiler

Basic Regular Expressions

. match a single character

[] matches multiple characters in the set range

[^] matches any single character outside the specified range

^ Beginning Locator

$ Behavior Locator

^$ matching Blank lines

* one of the qualifiers itself does not represent any character used to specify the preceding character to appear any time, including 0 times.

+ Qualifier One of the preceding characters appears at least once

| a relationship that represents or

() represents a set of optional values | () represents a set of optional values

. * Any character of any length

\? match the preceding character once or 0 times

\< the trailing character must appear as the first word

\> front character must appear as a suffix

\d Digital Match

\d non-digit matching

\s white space character matching

\s non-whitespace character matching

\{m,n\} \ is used to escape, prevents {} from being parsed by bash , matches the preceding character at least M times, up to N times , \{1,\} represents at least once, up to no limit.

Operator Precedence

\ Escape Character

[] square brackets Expression

() grouping

*,+,? ,{m},{m,},{m,n} Qualifier

Normal characters follow from left to right

^,$ Locator

| or arithmetic

Grep searches the regular expression globally and prints lines of text

Grep [option] pattern [file]

[option] :

-C Prints only the number of lines that match the lines of text and does not display matching content

-I ignores case when matching

-H does not display prefix names for matching files when searching multiple files

-l lists only the file name of the file containing the text line, and does not display the specific content.

-S does not display error messages about nonexistent or unreadable files

-V displays only lines of text that do not match

-W matches entire word

-X matches the entire line of text

-R Recursive search

-Q Suppresses output of any matching results in the form of a status code,0 means that matching lines of text are found

-E supports extended regular expressions

-P supports perl Regular Expressions

-F does not support regular expressions, and patterns are written in the literal sense

LINUX common Commands (iv)

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.