Some commands for Linux regular expressions and regular expressions

Source: Internet
Author: User
Tags egrep

Regular expression is a kind of requirement to deal with a lot of complicated data, to do fast searching, fast matching, fast substitution and deletion. Common regular expression commands have Grep,sed,awk (Three Musketeers) vi,egrep. The extended regular expressions are also supported by Egrep and awk.

Let's take a look at these commands. VI and VIM are introduced later.



Grep:

-V: Excludes matching content.

-I: Ignore case.

-O: Outputs only matching content.

-N: The line number is displayed at the beginning.

-e: Extended Regular Expression (=EGREP).

--color=auto: Supports color.



SED: Outputs both the matching content and the output of the source content intact.

S: Replace. (Format S/source string/replace string/)

G: Global. Generally used with S. (S/source string/replace string/g)

P: Print. Can be used with SG (S/source string/replace STRING/GP)

W File: Save to file.

D: Delete.

A: Append.

I: Insert in front.

C: Modify.

Y: Convert by character.

-F Script-file: Use Script-file to run file files. (Format: sed-f sed.sh test.txt)

-N: Silent mode output. (Output only matching content)

-I: Modify the source file.

-R: Supports extended regular.



Regular expression technology:

. : any single character.

*: matches the preceding character 0 or more times.

. *: Matches any number of characters.

[]: matches any single character within [].

^: Matches the beginning of the string.

$: Matches the line end of a string.

^$: Blank line.

\{m,n\}: Matches the previous character repeats m-n times.

\{m,\}: Matches the preceding character repeat at least m times.

\{,n\}: Matches the preceding character repeats up to n times.

Where \{\} uses {} for an extended regular expression.

\ (string\) and \ n: \ n (using \1,\2...\9) is the content of string.

An extended regular expression:

+: Repeat the previous character once in a shipment multiple times.

? : Repeats the preceding character 0 or one time.

| : matches the preceding or following character.

(): Matches the regular collection.

{M,n}: Repeats the previous character m-n times.

Posix:[] The character set within:

[: Alpha:] letter [: blank:] space or Tab character

[:d Igit:] Number [: Upper:] Uppercase

[:p UNCT:] punctuation [: lower:] lowercase letters

[: Space:] Blank character [: Alnum:] Letter or numeric character








Some commands for Linux regular expressions and regular expressions

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.