Regular two

==============================

00. Course Review Description
Symbol 1 role) system
a easy search to find information (file name data in the file contents)
b represent some special significance, for us to operate ~. ..
c facilitate the analysis with the Three Musketeers file content filter
2) system common symbol classification
system of special symbols
! basis symbol: $ (histroy) | #
quote symbol: "" (will do some special symbol parsing)
'' (WYSIWYG)
`` (quotation marks inside the execution of commands results to the call out command process)
the orientation symbols:> >> 2> 2 >> < (tr xargs) << EOF ( information for generating a multi-line)
route sign: .. ~ -
logic symbols: && and and the foregoing condition is satisfied (true), the latter performs operation
|| or front or condition is not satisfied (false), operation of the back
system wildcard: !!! for matching file names
match the symbol: * Note that the model placement
sequence symbol : {} {} {01..05} 01..05..2 {01,03,07}
{} {1..5} A..D
fast backup data mode:
CP / etc / {the hosts , .bak}
implementations quickly restore data:
CP /etc/hosts{.bak,}

system is the symbol: means for matching file contents!

01. Description of Symbols regular (trio for binding a command for editing file processing or filtering)
prepared simulation test files
CAT >> ~ / oldboy_test.txt the EOF <<
the I AM Oldboy Teacher!
The I Teach Linux.

I like badminton ball ,billiard ball and chinese chess!
my blog is http://oldboy.blog.51cto.com
our site is http://www.etiantian.org
my qq num is 49000448.

not 4900000448.
my god ,i am not oldbey,but OLDBOY!
EOF

The basis of regular symbol: basic regular expression (BRE)
extended regular symbol: extended regular expression (ERE)

basic regular symbols:
A sharp corners symbol: ^
to information about what the beginning to filter out
needs 01: will the information I the beginning are filtered out
[[email protected] ~] # grep "the I ^" ~ / oldboy_test.txt
the I AM Oldboy Teacher!
the I Teach Linux.
the I like Badminton Ball, Billiard Ball and chinese Chess!

Demand 02: I will not be at the beginning of the information are filtered out
[[email protected] ~] # grep -v " ^ I" ~ / oldboy_test.txt

my blog is http://oldboy.blog.51cto.com
our site is http://www.etiantian.org
my qq num is 49000448.

not 4900000448.
my god ,i am not oldbey,but OLDBOY!

Business needs: web service profile please streamline the process
grep -v "^ #" nginx.conf.default> nginx.conf

the Find / The -type f -name "^ Oldboy" error
find / -type f -name "oldboy * "correct

b dollar sign: $
to end what information to filter out
the needs of 01: Please find information ends with m, and displays the information on one line and two lines under the
[[email protected] ~] # grep "$ m" -A 2 -B. 1 ~ / oldboy_test.txt
the I like Badminton Ball, Billiard Ball and chinese Chess!
My Blog IS http://oldboy.blog.51cto.com
Our Site IS HTTP: // WWW. etiantian.org
My QQ NUM IS 49000448.

error Description:
how to confirm the end of each line of information spaces
method a:
CAT ~ -A / oldboy_test.txt
My Blog IS $ http://oldboy.blog.51cto.com
method two:
Vim enter the command line mode ---: List the SET

c sharp dollar sign: $ ^
remove the document hollow line information
grep "^ $" ~ / oldboy_test.txt
grep -v "^ $" ~ / oldboy_test.txt

D dot notation:
indicates a match any and only one character
[[email protected] ~] # grep " . "~ / oldboy_test.txt
the I AM Oldboy Teacher!
the I the Teach Linux.
the I like Badminton Ball, Billiard Ball and chinese Chess!
My Blog IS http://oldboy.blog.51cto.com
Our Site IS HTTP: // the WWW. etiantian.org
My QQ NUM IS 49000448.
Not 4900000448.
My God, I AM Not oldbey, But Oldboy!
[[email protected] ~] # grep "." ~ / -o oldboy_test.txt
the I

A
m

O
L

E asterisk symbol: *
front asterisk character matches zero or more consecutive times 0?
[[email protected] ~] # echo aababababb | grep "ab *"-the
the
ab &
ab &
ab &
ABB
[[email protected] ~] # echo aababababb | grep "A * B *" -o
AAB
ab &
ab &
ABB

F and point composition asterisk: *
matches all information
grep "*." ~ / oldboy_test.txt

demand 01: find the line beginning with m and ending with the line m, filter out
grep. "^ m * m $" ~ / oldboy_test.txt
My Blog iS http://oldboy.blog .51cto.com

demand 02: filters line part:
in m o to the end of the information
my blog is http: // o
Description: symbol having regular characteristics when greedy matching data information
[[email protected] ~ .cn] # grep "m ^. * O" ~ / oldboy_test.txt
My Blog IS http://oldboy.blog.51cto.com
My God, I AM Not oldbey, But Oldboy!
[@ Oldboy-Xiaodao the root. com.cn ~] # grep "^ m . * / o" ~ / oldboy_test.txt
my blog is http://oldboy.blog.51cto.com
Description: Avoid greed characteristic way, it is the only line of information specified node information

g translation symbol: \
1) will be some meaningful symbols translates, into a common symbol

demands: end of the line to remove the information.
[[email protected] ~] # grep "\ $." ~ /oldboy_test.txt
the I the Teach Linux.
My QQ NUM IS 49000448.
not 4900000448.

2) The meaning of symbols that have no translation, into meaningful symbols
\ n newline Linux
\ r newline Windows
\ t tabulation symbol (tab)

3) may be extended regular symbols into ordinary regular grep sed command allows direct identification '
[[email protected] oldboy_dir] # grep "O \?" ~ / Oldboy_test03.txt
Gd
God
Good
a goood
gooood

H bracket symbol: []
matching brackets each character, and the relationship is or relationship matching
demand: identify and document oldboy oldbey two words information
grep "oldb [oe] y" ~ / oldboy_test.txt

Enterprise Applications: find files alphanumeric information
grep "[0-9a-zA-Z ]" ~ / oldboy_test.txt

i caret and brackets in combination: [^]
of character information matching brackets exclusion
grep "[^ 0-9a-zA- Z]" ~ / oldboy_test.txt --- alphanumeric are excluded, only leaving symbol information
caret and bracket combination of: ^ []
with the character in the brackets as the beginning of a line matching character
grep "^ [Im]" ~ / oldboy_test.txt

Conclusion: Note the regular sign
. ① filtration treatment according to each line of information
② to a positive sign is prohibited Chinese expression.
③ positive color information attached --color = auto / then filtered - Color.
④ symbol may be a regular basis trio. sed direct identification command awk grep
5. the extended regular symbols may not be directly identified in the second oldest and youngest trio command
sed command like a regular identification symbol: -R & lt sed
grep command to identify like regular symbol: egrep / grep -E

extended regular symbol :
a plus sign: +
matching character preceded by a consecutive number 1 appears once or more
[[email protected] ~] # egrep "0+" ~ / oldboy_test.txt
My QQ NUM IS 49000448.
Not 4900000448.
[[email protected] ~] # grep -E "0+" ~ / oldboy_test.txt
My QQ NUM IS 49000448.
Not 4900000448.

grep -E "[0-9] +" ~ / oldboy_test .txt -o

The ultimate goal of
cat >> ~ / oldboy_test02.txt << EOF
Zhao 110101199901045121
money 110101199901045121
Sun 11010119990104512X
Lee 110101299901045121
Chen oldboy
week 110101199981045121
Wu 110101199901045121
Zheng 11010149990104512X
Liu oldgirl
king 110101199908045121
von 110111199901045121
EOF
problem solving:
[[email protected] ~] # egrep -v "[0-9X ] +" ~ / oldboy_test02.txt
Chen oldboy
Liu oldgirl
[[email protected] ~] # egrep "[^ 0-9X] +" ~ / oldboy_test02. txt
Zhao 110101199901045121
money 110101199901045121
Sun 11010119990104512X
Lee 110101299901045121
Chen oldboy
week 110101199981045121
110101199901045121 Wu
Zheng 11010149990104512X
Liu oldgirl
king 110101199908045121
von 110111199901045121

b pipe symbol: |
or relation symbol
[[email protected] ~] # egrep "Oldboy | oldbey" ~ / oldboy_test.txt
the I AM Oldboy Teacher!
My Blog IS HTTP: //oldboy.blog.51cto .com
My god, i AM not oldbey, But Oldboy!

enterprise applications: information may have # blank line in the configuration file, it must be filtered out do not show
egrep -v "^ # | ^ $ " file name

Extension: How to use sed completed + | filtering
1) how to filter the numerical information
sed -rn '/ [0-9] + / P' ~ / oldboy_test.txt
2) how to filter the two strings of information (Oldboy oldbey)
sed - NR '/ Oldboy | oldbey / P' ~ / oldboy_test.txt

C parentheses :( symbols)
to a plurality of character information is summarized as a whole
[[email protected] ~] # egrep "( oldboy)" ~ /oldboy_test.txt
the I AM Oldboy Teacher!
My Blog IS http://oldboy.blog.51cto.com

Requirements: identify and document oldboy oldbey two words information
[[email protected] ~] # egrep "(oldboy) | (oldbey)" ~ / oldboy_test.txt
the I AM oldboy Teacher!
My Blog IS HTTP : //oldboy.blog.51cto.com
! My God, I AM Not oldbey, But Oldboy
[[email protected] ~] # egrep "Oldb (O | E) Y" ~ / oldboy_test.txt
the I Teacher Oldboy AM!
My Blog iS http://oldboy.blog.51cto.com
My God, I AM Not oldbey, But Oldboy!

after a reference to the operation of the forward (Sed)
[[email protected]. ~ CN] # echo "123456" | -R & lt Sed "(. *) # S # <\. 1> #G"
<123456>
[[email protected] ~] # echo "123456" | Sed - R & lt "S # (..) (..) (..) # <\. 1> <\ 2> <\. 3> #G"
<12 is> <34 is> <56 is>

Enterprise Applications Practice:
01. modify the configuration file content
[[email protected] ~] # grep "^ S. * UX =" / etc / SELinux / config
SELINUX = Disabled
[[email protected]. ~ CN] -rn # Sed "S # (S. ^ * = UX) # \ 1enforcing # G" / etc / SELinux / config
[[email protected] ~] # -rn Sed "S # ( UX = S. * ^) # \ 1enforcing GP # "/ etc / SELinux / config
the SELINUX = enforcingdisabled
[[email protected] ~] # -rn Sed" S # (S. ^ * = UX). # * \ 1enforcing # gp "/ etc / SELinux / config
SELINUX = enforcing
Note: You can replace commands into the script, enabling rapid deployment operations

02. batch modify file name (job)
oldboy01.txt
oldboy02.txt
oldboy03. TXT
oldboy04.txt
oldboy05.txt
oldboy06.txt
oldboy07.txt
oldboy08.txt
oldboy09.txt
oldboy10.txt
above modifications to the file extension .jpg

D symbols brackets: {}
specifies a character spent continuously expanding number how many previous match
* matches zero or more times in a row
+ 1 or more consecutive matches
1) {n, m} n represents the number m of consecutive minimum match indicates how many times a maximum consecutive matches
[[email protected] oldboy_dir] # egrep "3,4- {0}" ~ / oldboy_test.txt
My QQ NUM IS 49000448.
Not 4900000448.
[[email protected] oldboy_dir] # egrep "3,4- {0}" ~ / oldboy_test.txt -o
000
0000

2) n {n} indicates that only the n-th consecutive matches
[root @ oldboy- oldboy_dir xiaodao.com.cn] # egrep "{0}. 3" ~ / oldboy_test.txt
My QQ NUM IS 49000448.
Not 4900000448.
[[email protected] oldboy_dir] # egrep "{0}. 3" ~ -o /oldboy_test.txt
000
000

3) {n,} n represents consecutive matches at least n times, up to no limit
[[email protected] oldboy_dir] # egrep "0. 3 {,}" ~ / oldboy_test.txt
My QQ NUM IS 49000448.
Not 4900000448.
[[email protected] oldboy_dir] # egrep "0. 3 {,}" ~ / oldboy_test.txt -o
000
00000

. 4) {, m} m represents up to n times in a row match, at least once 0
[ oldboy_dir [email protected]] # egrep "{0,. 3}" ~ / oldboy_test.txt
the I AM Oldboy Teacher!
the I Teach Linux.

the I like Badminton Ball, Billiard Ball and chinese Chess!
My Blog HTTP IS: //oldboy.blog.51cto.com
Our Site IS http://www.etiantian.org
My QQ NUM IS 49000448.

not 4900000448.
My god, i AM not oldbey, But Oldboy!
[[email protected] oldboy_dir]# egrep "0{,3}" ~/oldboy_test.txt -o
000
000
00
[[email protected] oldboy_dir]# egrep "0{,4}" ~/oldboy_test.txt -o
000
0000
0

e question mark:?
* + {}
indicates that a question mark matches zero or 1 characters appear
CAT >> ~ / oldboy_test03.txt the EOF <<
Gd
God
Good
a goood
gooood
the EOF

Demo Description:
[[email protected]. oldboy_dir CN] # grep "O *" ~ / oldboy_test03.txt
Gd
God
Good
a goood
gooood
[[email protected] oldboy_dir] # grep "+ O" ~ / oldboy_test03.txt
[[email protected]. oldboy_dir CN] # egrep "+ O" ~ / oldboy_test03.txt
God
Good
a goood
gooood
[[email protected] oldboy_dir] # egrep "O?" ~ / oldboy_test03.txt
Gd
God
Good
a goood
gooood
[[email protected] oldboy_dir]# egrep "o?" ~/oldboy_test03.txt -o
o
o
o
o
o
o
o
o
o
o






Guess you like

Origin www.cnblogs.com/nsh123/p/12158719.html