Linux: Regular Expressions

Source: Internet
Author: User

Regular expressions: Formal notation, regular notation (Regular expression) regular expressions are described using a single string, matching a series of strings that conform to a rule of a sentence.

1) command format;

grep "Regular" string file

2) Command parameters

^ with what begins

$ with what end

\ escape Character

* Repeat 0 or more of the preceding characters

. * Match All characters

[] List the characters you want inside

[N1-N2] lists the range of characters that you want to include

. Have an arbitrary character

[^]# matches a character not in the specified range

\(.. \) Tag matching characters

\< anchoring the beginning of a word

>\ anchoring the end of a word

x\{m\}# repeat character X, m times

x\{m,\}# repeat character X, at least m times

x{m,n}# repeat character X, at least m times cannot be more than n times

\w matches literal and numeric characters [a-za-z0-9]

3) Command Introduction:

Command: Ps-ef |grep SVN find the specified process

Command: Ps-ef|grep svn-c or Ps-ef|grep-c svn to find the specified number of processes

Command: Cat text.txt|grep-f test2.txt Read keywords from file for search

Command: grep ' keyword ' test. TXT Find keyword search from file

Command: grep ' keyword ' test. TXT test. txt2 Finding keyword searches from multiple files

Command: PS aux | grep \[s] sh or PS aux |grep ssh| Grep-v "grep" grep does not show itself process

Command: Cat Test.txt|grep^u find the line content that has the U start

Command: Cat test.txt|grep ^[^u] Output line content that does not start with u

Command: Cat test.txt|grep hat$ Output The line contents of Hat end

Command: Cat test.txt|grep-e "Ed|at" displays content with an Ed or at character

Command: grep ' {a-z}\{7\} ' *.txt displays the current directory under the. TXT end-of-file all rows containing a string of at least 7 consecutive lowercase characters per string

Linux: 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.