Linux Regular Expressions-basic regular expressions (based on grep)

Source: Internet
Author: User
Tags egrep

Linux Regular Expressions:

In short, a regular expression is a set of rules and methods that are defined for processing a large number of strings, such as assuming @ represents 123456,! for ABCDE. By defining these special symbols, the system administrator can quickly filter, replace, or output the required characters.


Considerations for using Regular expressions:

1.linux regular is usually handled by the behavioral unit.

2.alias grep= ' grep--color=auto ', the lecture takes grep for example. (Note: In order to make the following case clearer, please execute this line before doing the following)

3. Note the character set, Lc_all=c

Regular expressions in Linux. It is mainly the regular expression of awk, sed, and grep (Egrep) Three Musketeers.


A, the underlying regular expression (based on grep)

1.^a means searching for content that starts with a

2.a$ means searching for content ending in a

3.^$ represents a blank line, not a space

4.. Represents and can only represent any one character

5. \ \. Just represent the point itself, escape the symbol, let the character with special meaning, take off the vest,

6. * Repeat 0 or more of the preceding characters

7. * Match all characters. ^.* begins with any number of characters,. *$ ends with any number of characters

^.* based on the preceding single character, we know that ^.* matches content that begins with any number of strings.

8. [ABC] matches any one of the characters in the character set [A-z].

9. [^ABC] matches content that does not contain any characters after ^

[^a-z] does not contain lowercase letters

[^0-9] does not contain numbers

Ten. A\{n,m\} repeats N to M times, the previous repeating character. If you use Egrep, you can remove the slash.

\{n,\} repeats at least n times, preceding a repeating character. If you use Egrep, you can remove the slash.

\{n\} repeats n times, before a repeating character. If you use Egrep, you can remove the slash.

\{,m}\ repeats up to M times-best not to use.

[Email protected]_back ~]# grep. * "test.log" = = matches 0 or more, so there is a blank line.)

Linux Regular Expressions:

In short, a regular expression is a set of rules and methods that are defined for processing a large number of strings, such as assuming @ represents 123456,! for ABCDE. By defining these special symbols, the system administrator can quickly filter, replace, or output the required characters.

Considerations for using Regular expressions:

1.linux regular is usually handled by the behavioral unit.

2.alias grep= ' grep--color=auto ', the lecture takes grep for example.

3. Note the character set, Lc_all=c

Regular expressions in Linux. It is mainly the regular expression of awk, sed, and grep (Egrep) Three Musketeers.


A, the underlying regular expression (based on grep)

1.^a means searching for content that starts with a

2. $a means search for content ending in a

3.^$ represents a blank line, not a space

4.

[Email Protected]_back ~]# grep.] "test.log" = = matches any one character, at least one, so there is no blank line.

Linux Regular Expressions:

In short, a regular expression is a set of rules and methods that are defined for processing a large number of strings, such as assuming @ represents 123456,! for ABCDE. By defining these special symbols, the system administrator can quickly filter, replace, or output the required characters.

Considerations for using Regular expressions:

1.linux regular is usually handled by the behavioral unit.

2.alias grep= ' grep--color=auto ', the lecture takes grep for example.

3. Note the character set, Lc_all=c

Regular expressions in Linux. It is mainly the regular expression of awk, sed, and grep (Egrep) Three Musketeers.

A, the underlying regular expression (based on grep)

1.^a means searching for content that starts with a

2. $a means search for content ending in a

3.^$ represents a blank line, not a space

4.


[Email protected]_back ~]# grep-v "^$" Test.log

Linux Regular Expressions:

In short, a regular expression is a set of rules and methods that are defined for processing a large number of strings, such as assuming @ represents 123456,! for ABCDE. By defining these special symbols, the system administrator can quickly filter, replace, or output the required characters.

Considerations for using Regular expressions:

1.linux regular is usually handled by the behavioral unit.

2.alias grep= ' grep--color=auto ', the lecture takes grep for example.

3. Note the character set, Lc_all=c

Regular expressions in Linux. It is mainly the regular expression of awk, sed, and grep (Egrep) Three Musketeers.

A, the underlying regular expression (based on grep)

1.^a means searching for content that starts with a

2. $a means search for content ending in a

3.^$ represents a blank line, not a space

4.


[Email protected]_back ~]# grep-vn "^$" Test.log

1:linux Regular Expressions:

2: In a nutshell, a regular expression is a set of rules and methods that are defined to handle a large number of strings, such as assuming @ represents 123456,! for ABCDE. By defining the paving of these special symbols, the system administrator can quickly filter, replace, or output the required characters.

3: Use Regular expression considerations:

4:1.linux is usually dealt with in a behavioral unit.

5:2.alias grep= ' grep--color=auto ', the lecture is taking grep for example.

6:3. Note Character Set, lc_all=c

Regular expressions in the 7:linux. It is mainly the regular expression of awk, sed, and grep (Egrep) Three Musketeers.

10:a, base regular expression (grep based)

11:1.^a means searching for content that starts with a

12:2. $a means searching for content ending in a

13:3.^$ represents a blank line, not a space

14:4.

[Email protected]_back ~]# grep-v n "^$" Test.log

grep: ^$: No file or directory

Test.log: In a nutshell, a regular expression is a set of rules and methods that are defined to handle a large number of strings, such as assuming @ represents 123456,! for ABCDE. By defining the paving of these special symbols, the system administrator can quickly filter, replace, or output the required characters.

Test.log: Use Regular expression considerations:

Test.log:2.alias grep= ' grep--color=auto ', the lecture is taking grep for example.

Test.log:3. Note Character Set, lc_all=c

Test.log:

Test.log:

Test.log:a, base regular expression (grep based)

Test.log:1.^a means searching for content that starts with a

Test.log:2. $a means searching for content ending in a

test.log:3.^$ represents a blank line, not a space

Test.log:4.

[Email protected]_back ~]# grep-v-n "^$" Test.log

1:linux Regular Expressions:

2: In a nutshell, a regular expression is a set of rules and methods that are defined to handle a large number of strings, such as assuming @ represents 123456,! for ABCDE. By defining the paving of these special symbols, the system administrator can quickly filter, replace, or output the required characters.

3: Use Regular expression considerations:

4:1.linux is usually dealt with in a behavioral unit.

5:2.alias grep= ' grep--color=auto ', the lecture is taking grep for example.

6:3. Note Character Set, lc_all=c

Regular expressions in the 7:linux. It is mainly the regular expression of awk, sed, and grep (Egrep) Three Musketeers.

10:a, base regular expression (grep based)

11:1.^a means searching for content that starts with a

12:2. $a means searching for content ending in a

13:3.^$ represents a blank line, not a space

14:4.

[[Email Protected]_back ~]# grep "$" test.log

Linux Regular Expressions:

In short, a regular expression is a set of rules and methods that are defined for processing a large number of strings, such as assuming @ represents 123456,! for ABCDE. By defining these special symbols, the system administrator can quickly filter, replace, or output the required characters.

Considerations for using Regular expressions:

1.linux regular is usually handled by the behavioral unit.

2.alias grep= ' grep--color=auto ', the lecture takes grep for example.

3. Note the character set, Lc_all=c

Regular expressions in Linux. It is mainly the regular expression of awk, sed, and grep (Egrep) Three Musketeers.



A, the underlying regular expression (based on grep)

1.^a means searching for content that starts with a

2. $a means search for content ending in a

3.^$ represents a blank line, not a space

4.

[Email protected]_back ~]# grep "C $" test.log

3. Note the character set, Lc_all=c

[Email Protected]_back ~]# grep.] Test.log

Linux Regular Expressions:

In short, a regular expression is a set of rules and methods that are defined for processing a large number of strings, such as assuming @ represents 123456,! for ABCDE. By defining these special symbols, the system administrator can quickly filter, replace, or output the required characters.

Considerations for using Regular expressions:

1.linux regular is usually handled by the behavioral unit.

2.alias grep= ' grep--color=auto ', the lecture takes grep for example.

3. Note the character set, Lc_all=c

Regular expressions in Linux. It is mainly the regular expression of awk, sed, and grep (Egrep) Three Musketeers.

A, the underlying regular expression (based on grep)

1.^a means searching for content that starts with a

2. $a means search for content ending in a

3.^$ represents a blank line, not a space

4.

[Email protected]_back ~]# grep "\." Test.log

In short, a regular expression is a set of rules and methods that are defined for processing a large number of strings, such as assuming @ represents 123456,! for ABCDE. By defining these special symbols, the system administrator can quickly filter, replace, or output the required characters.

1.linux regular is usually handled by the behavioral unit.

2.alias grep= ' grep--color=auto ', the lecture takes grep for example.

3. Note the character set, Lc_all=c

1.^a means searching for content that starts with a

2. $a means search for content ending in a

3.^$ represents a blank line, not a space

4.


[Email protected]_back ~]# grep "Rep" Test.log

2.alias grep= ' grep--color=auto ', the lecture takes grep for example.

Regular expressions in Linux. It is mainly the regular expression of awk, sed, and grep (Egrep) Three Musketeers.

A, the underlying regular expression (based on grep)

[Email protected]_back ~]# grep "grep" Test.log

2.alias grep= ' grep--color=auto ', the lecture takes grep for example.

Regular expressions in Linux. It is mainly the regular expression of awk, sed, and grep (Egrep) Three Musketeers.

A, the underlying regular expression (based on grep)

[Email protected]_back ~]# grep ". $" Test.log

Linux Regular Expressions:

In short, a regular expression is a set of rules and methods that are defined for processing a large number of strings, such as assuming @ represents 123456,! for ABCDE. By defining these special symbols, the system administrator can quickly filter, replace, or output the required characters.

Considerations for using Regular expressions:

1.linux regular is usually handled by the behavioral unit.

2.alias grep= ' grep--color=auto ', the lecture takes grep for example.

3. Note the character set, Lc_all=c

Regular expressions in Linux. It is mainly the regular expression of awk, sed, and grep (Egrep) Three Musketeers.

A, the underlying regular expression (based on grep)

1.^a means searching for content that starts with a

2. $a means search for content ending in a

3.^$ represents a blank line, not a space

4.

[Email protected]_back ~]# grep "\.$" Test.log

4.

[Email protected]_back ~]# grep "\.*$" Test.log

Linux Regular Expressions:

In short, a regular expression is a set of rules and methods that are defined for processing a large number of strings, such as assuming @ represents 123456,! for ABCDE. By defining these special symbols, the system administrator can quickly filter, replace, or output the required characters.

Considerations for using Regular expressions:

1.linux regular is usually handled by the behavioral unit.

2.alias grep= ' grep--color=auto ', the lecture takes grep for example.

3. Note the character set, Lc_all=c


[[Email Protected]_back ~]# grep]. * "Test.log

Linux Regular Expressions:

In short, a regular expression is a set of rules and methods that are defined for processing a large number of strings, such as assuming @ represents 123456,! for ABCDE. By defining these special symbols, the system administrator can quickly filter, replace, or output the required characters.

Considerations for using Regular expressions:

1.linux regular is usually handled by the behavioral unit.

2.alias grep= ' grep--color=auto ', the lecture takes grep for example.

3. Note the character set, Lc_all=c

Regular expressions in Linux. It is mainly the regular expression of awk, sed, and grep (Egrep) Three Musketeers.



A, the underlying regular expression (based on grep)

1.^a means searching for content that starts with a

2. $a means search for content ending in a

3.^$ represents a blank line, not a space

4.

[Email Protected]_back ~]# grep.] Test.log

Linux Regular Expressions:

In short, a regular expression is a set of rules and methods that are defined for processing a large number of strings, such as assuming @ represents 123456,! for ABCDE. By defining these special symbols, the system administrator can quickly filter, replace, or output the required characters.

Considerations for using Regular expressions:

1.linux regular is usually handled by the behavioral unit.

2.alias grep= ' grep--color=auto ', the lecture takes grep for example.

3. Note the character set, Lc_all=c

Regular expressions in Linux. It is mainly the regular expression of awk, sed, and grep (Egrep) Three Musketeers.

A, the underlying regular expression (based on grep)

1.^a means searching for content that starts with a

2. $a means search for content ending in a

3.^$ represents a blank line, not a space

4.


[Email protected]_back ~]# grep ". $" Test.log

Linux Regular Expressions:

In short, a regular expression is a set of rules and methods that are defined for processing a large number of strings, such as assuming @ represents 123456,! for ABCDE. By defining these special symbols, the system administrator can quickly filter, replace, or output the required characters.

Considerations for using Regular expressions:

1.linux regular is usually handled by the behavioral unit.

2.alias grep= ' grep--color=auto ', the lecture takes grep for example.

3. Note the character set, Lc_all=c

Regular expressions in Linux. It is mainly the regular expression of awk, sed, and grep (Egrep) Three Musketeers.

A, the underlying regular expression (based on grep)

1.^a means searching for content that starts with a

2. $a means search for content ending in a

3.^$ represents a blank line, not a space

4.


[Email protected]_back ~]# grep ". *$" Test.log

Linux Regular Expressions:

In short, a regular expression is a set of rules and methods that are defined for processing a large number of strings, such as assuming @ represents 123456,! for ABCDE. By defining these special symbols, the system administrator can quickly filter, replace, or output the required characters.

Considerations for using Regular expressions:

1.linux regular is usually handled by the behavioral unit.

2.alias grep= ' grep--color=auto ', the lecture takes grep for example.

3. Note the character set, Lc_all=c

Regular expressions in Linux. It is mainly the regular expression of awk, sed, and grep (Egrep) Three Musketeers.



A, the underlying regular expression (based on grep)

1.^a means searching for content that starts with a

2. $a means search for content ending in a

3.^$ represents a blank line, not a space

4.

[Email protected]_back ~]# grep "\.*" Test.log

Linux Regular Expressions:

In short, a regular expression is a set of rules and methods that are defined for processing a large number of strings, such as assuming @ represents 123456,! for ABCDE. By defining these special symbols, the system administrator can quickly filter, replace, or output the required characters.

Considerations for using Regular expressions:

1.linux regular is usually handled by the behavioral unit.

2.alias grep= ' grep--color=auto ', the lecture takes grep for example.

3. Note the character set, Lc_all=c

Regular expressions in Linux. It is mainly the regular expression of awk, sed, and grep (Egrep) Three Musketeers.



A, the underlying regular expression (based on grep)

1.^a means searching for content that starts with a

2. $a means search for content ending in a

3.^$ represents a blank line, not a space

4.

[Email protected]_back ~]# grep "grep" Test.log

2.alias grep= ' grep--color=auto ', the lecture takes grep for example.

Regular expressions in Linux. It is mainly the regular expression of awk, sed, and grep (Egrep) Three Musketeers.

A, the underlying regular expression (based on grep)

[Email protected]_back ~]# grep "\." Test.log

In short, a regular expression is a set of rules and methods that are defined for processing a large number of strings, such as assuming @ represents 123456,! for ABCDE. By defining these special symbols, the system administrator can quickly filter, replace, or output the required characters.

1.linux regular is usually handled by the behavioral unit.

2.alias grep= ' grep--color=auto ', the lecture takes grep for example.

3. Note the character set, Lc_all=c

1.^a means searching for content that starts with a

2. $a means search for content ending in a

3.^$ represents a blank line, not a space

4.

[Email protected]_back ~]# grep "C $" test.log

3. Note the character set, Lc_all=c

[Email protected]_back ~]# grep-v-n "^$" Test.log

1:linux Regular Expressions:

2: In a nutshell, a regular expression is a set of rules and methods that are defined to handle a large number of strings, such as assuming @ represents 123456,! for ABCDE. By defining the paving of these special symbols, the system administrator can quickly filter, replace, or output the required characters.

3: Use Regular expression considerations:

4:1.linux is usually dealt with in a behavioral unit.

5:2.alias grep= ' grep--color=auto ', the lecture is taking grep for example.

6:3. Note Character Set, lc_all=c

Regular expressions in the 7:linux. It is mainly the regular expression of awk, sed, and grep (Egrep) Three Musketeers.

10:a, base regular expression (grep based)

11:1.^a means searching for content that starts with a

12:2. $a means searching for content ending in a

13:3.^$ represents a blank line, not a space

14:4.

[Email protected]_back ~]# grep "^linux" Test.log

Linux Regular Expressions:

Regular expressions in Linux. It is mainly the regular expression of awk, sed, and grep (Egrep) Three Musketeers. 、


[Email protected]_back ~]# Cat Test.log

[AAA]

Cfg1=aaa

xxxx=bbb

Cfg2=ccc

Cfg3=ddd

[BBB]

Cfg1=eee

Yyyy=fff

Cfg2=ggg

Cfg3=hhh

Cfg4=iii

[CCC]

Cfg1=jjj

Zzzz=kkk

Cfg2=lll

Cfg2=mmm

cfg2=nnn

[Email protected]_back ~]# grep "c*" Test.log

[AAA]

Cfg1=aaa

xxxx=bbb

Cfg2=ccc

Cfg3=ddd

[BBB]

Cfg1=eee

Yyyy=fff

Cfg2=ggg

Cfg3=hhh

Cfg4=iii

[CCC]

Cfg1=jjj

Zzzz=kkk

Cfg2=lll

Cfg2=mmm

cfg2=nnn

[Email protected]_back ~]# grep-o "c*" Test.log

C

C

Ccc

C

C

C

C

C

Ccc

C

C

C

C

[Email protected]_back ~]# grep-o ". *" Test.log

[AAA]

Cfg1=aaa

xxxx=bbb

Cfg2=ccc

Cfg3=ddd

[BBB]

Cfg1=eee

Yyyy=fff

Cfg2=ggg

Cfg3=hhh

Cfg4=iii

[CCC]

Cfg1=jjj

Zzzz=kkk

Cfg2=lll

Cfg2=mmm

cfg2=nnn

[[Email Protected]_back ~]# alias grep= ' grep--color=auto '

[Email protected]_back ~]# grep "c*" Test.log [AAA]

Cfg1=aaa

xxxx=bbb

Cfg2=ccc

Cfg3=ddd

[BBB]

Cfg1=eee

Yyyy=fff

Cfg2=ggg

Cfg3=hhh

Cfg4=iii

[CCC]

Cfg1=jjj

Zzzz=kkk

Cfg2=lll

Cfg2=mmm

cfg2=nnn

[Email protected]_back ~]# grep-o "c*" Test.log

C

C

Ccc

C

C

C

C

C

Ccc

C

C

C

C

[Email protected]_back ~]# grep-o ". *" Test.log

[AAA]

Cfg1=aaa

xxxx=bbb

Cfg2=ccc

Cfg3=ddd

[BBB]

Cfg1=eee

Yyyy=fff

Cfg2=ggg

Cfg3=hhh

Cfg4=iii

[CCC]

Cfg1=jjj

Zzzz=kkk

Cfg2=lll

Cfg2=mmm

cfg2=nnn

[Email protected]_back ~]# grep "[ABC]" Test.log

[AAA]

Cfg1=aaa

xxxx=bbb

Cfg2=ccc

Cfg3=ddd

[BBB]

Cfg1=eee

Cfg2=ggg

Cfg3=hhh

Cfg4=iii

[CCC]

Cfg1=jjj

Cfg2=lll

Cfg2=mmm

cfg2=nnn

[Email protected]_back ~]# grep "[A-z]" Test.log

[AAA]

Cfg1=aaa

xxxx=bbb

Cfg2=ccc

Cfg3=ddd

[BBB]

Cfg1=eee

Yyyy=fff

Cfg2=ggg

Cfg3=hhh

Cfg4=iii

[CCC]

Cfg1=jjj

Zzzz=kkk

Cfg2=lll

Cfg2=mmm

cfg2=nnn

[Email protected]_back ~]# grep "[0-9]" Test.log

Cfg1=aaa

Cfg2=ccc

Cfg3=ddd

Cfg1=eee

Cfg2=ggg

Cfg3=hhh

Cfg4=iii

Cfg1=jjj

Cfg2=lll

Cfg2=mmm

cfg2=nnn


[Email protected]_back ~]# VI test.log

[AAA]

Cfg1=aaa

. xxxx=bbb

Cfg2=ccc

. cfg3=ddd

[BBB]

Cfg1=eee

. yyyy=fff/

Cfg2=ggg

Cfg3=hhh

c.fg4=iii/

[CCC]

Cf.g1=jjj

zzzz=kkk/

Cfg.2=lll.

"Test.log" 17L, 154C written

[Email protected]_back ~]# grep "[\.,/]" Test.log

. xxxx=bbb

. cfg3=ddd

. yyyy=fff/

c.fg4=iii/

Cf.g1=jjj

zzzz=kkk/

Cfg.2=lll.

[Email protected]_back ~]# grep "[^abc]" Test.log

[AAA]

Cfg1=aaa

. xxxx=bbb

Cfg2=ccc

. cfg3=ddd

[BBB]

Cfg1=eee

. yyyy=fff/

Cfg2=ggg

Cfg3=hhh

c.fg4=iii/

[CCC]

Cf.g1=jjj

zzzz=kkk/

Cfg.2=lll.

Cfg2=mmm

cfg2=nnn


[Email protected]_back ~]# VI test.log

[AAA]

cfg1=aaa00000

0.xxxx=bbb

Cfg2=ccc

.00cfg3=ddd

[bbb]0000

Cfg1=eee

. yy00yy=fff/

Cfg2=ggg

cfg3=hhh00000

c.fg400=iii/

[CCC]

Cf.g1=jjj

zzzz=kk000000000k/

Cfg.2=lll.

Cfg2=mmm

cfg2=nnn

"Test.log" 17L, 184C written

[Email protected]_back ~]# grep "0\{1,3\}" Test.log

cfg1=aaa00000

0.xxxx=bbb

.00cfg3=ddd

[bbb]0000

. yy00yy=fff/

cfg3=hhh00000

c.fg400=iii/

zzzz=kk000000000k/


[Email protected]_back ~]# grep "0\{1,\}" Test.log

cfg1=aaa00000

0.xxxx=bbb

.00cfg3=ddd

[bbb]0000

. yy00yy=fff/

cfg3=hhh00000

c.fg400=iii/

zzzz=kk000000000k/

[Email protected]_back ~]# grep "0\{2\}" Test.log

cfg1=aaa00000

.00cfg3=ddd

[bbb]0000

. yy00yy=fff/

cfg3=hhh00000

c.fg400=iii/

zzzz=kk000000000k/

[Email protected]_back ~]# egrep "0{1,3}" Test.log

cfg1=aaa00000

0.xxxx=bbb

.00cfg3=ddd

[bbb]0000

. yy00yy=fff/

cfg3=hhh00000

c.fg400=iii/

zzzz=kk000000000k/


grep General Common parameters:

-A: Search for data in a binary file as a text file

-C: Count the number of ' search strings ' found

-O: Only content matching regexp is displayed (used to count the number of times in the current article)

-I: Ignores case differences, so case is considered the same

-N: Show line numbers at the beginning

-V: Reverse selection, which shows the line without the ' search string ' content

-e: extended grep, i.e. Egrep

--color=auto: Highlight matching keywords in a specific color

#<-hint:-i-v for common parameters

-a:after, displays data that matches n rows after the string

-b:before, displays data that matches the first n rows of a string


On-line environmental fine case follow-up succession finishing:


This article is from the "Lanzhou Linux operation and Maintenance" blog, please be sure to keep this source http://linuxzkq.blog.51cto.com/9379412/1639502

Linux Regular Expressions-basic regular expressions (based on grep)

Related Article

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.