UNIX: ?????????? ?????????, POSIX/PCRE, GREP, SED - PowerPoint PPT Presentation

About This Presentation
Title:

UNIX: ?????????? ?????????, POSIX/PCRE, GREP, SED

Description:

Title: UNIX: , GREP, POSIX/PCRE Author: Last modified by: Created Date – PowerPoint PPT presentation

Number of Views:186
Avg rating:3.0/5.0
Slides: 38
Provided by: 5403151
Category:
Tags: grep | pcre | posix | sed | unix

less

Transcript and Presenter's Notes

Title: UNIX: ?????????? ?????????, POSIX/PCRE, GREP, SED


1
UNIX ?????????? ?????????, POSIX/PCRE, GREP,
SED
2
?????????? ?????????
  • Regular expressions (RegExp, RegEx)
  • ?????????? ???? ?????? ? ?????????????
    ??????????? ? ??????????? ? ??????
  • ????????????? ???????????? (wildcard characters)
  • ?????? (?????) - ?????? ??????? ??????.

3
????????? ?????????? ?????????
  • ????? ??? ????????? ???????? ? ??????
    ????????????????
  • ????????? ?????????? ?????????? ? ???????, ??
    ???????? ???????? ?????????? ????????? ?????
    ?????????.

4
??????? ???????
  • ????????????
  • - ????????? ?????????e ????????
  • graygrey
  • ???????????
  • () ?????????? ??????? ???????? ? ?????????
    ??????????
  • gr(ae)y

5
??????? ???????(???????????)
  • ?????????????
  • m, n
  • m,
  • , n
  • ? 0, 1
  • 0,
  • 1,
  • gogle ????????????? gogle, google ? ?.?., ??
    ?? ggle

6
?????????? ????????? ? UNIX
  • ????????? BRE (basic regular expressions) ??
    ?????? ?????? ????????? POSIX ??? ??????????
  • ?????? ????????????? ?? ??????????? ????????
    ?????????????
  • ?????? UNIX-??????? ?????????? ????? ??????????
    ????????? ?? ?????????.

7
POSIX ????????
  • ????? ????????
  • . ????? - ????? ??????
  • lt???????gt - ?????????? ?????? ?????
    ???????? ("????? ??")
  • lt???????gt - ?????????? ????? ????????
    ("????? ?????")
  • - ??????????? ?????????????????? ? ??????
    ???????? ("0-9" --?????)

8
?????????????? ? ????? ? POSIX
  • ??????????????
  • "?????????" ??? ???? ????????? 0,
  • ???? 1,
  • ? ?????????????? ???? 0,1
  • ?????
  • ???????? ? ?????? ??????
  • ???????? ? ????? ??????

9
??????????? ?????????? ?????????
  • ? ????????????? UNIX-?????????? ?????????
    ???????
  • ?
  • ??????? ???????????? ?????? \

10
PCRE ????????
  • Perl compatible regular expressions
  • i ??????????????????? ?????
  • m ?????????????? ?????.
  • "" ????????? ? ??????? ? ?????? ?????????
    ?????.
  • s ?????? "." (?????) ????????? ? ?
    ????????? ?????? (?? ????????? -- ???)
  • A ???????? ? ?????? ??????
  • E ?????????? ?????? "" ????????? ?????? ?
    ?????? ??????.
  • U ??????????? "????????" ??? ???????
    ?????????????? (???? ????? ?????????????? ?????
    "?", ????????????? ????????? ???? "??????").

11
??????
  • ??????? ?????? ???????????? ??? ???????????
    ??????? ???????? ? ?????????? ????????
  • ??????????? ? ???????? ?????? ? ???
  • ????????? ???????????

12
?????? ????????? ???????????
?????? ???????????? ??????????? ??????
a(bcbx)cc abccaxcc abccaxcc abccaxcc abccaxcc
a(?bcbx)cc abccaxcc abccaxcc abccaxcc abccaxcc
a(?bcbx)cc abccaxcc abccaxcc
a(?gtbcbx)cc abccaxcc ?? ?? abccaxcc ??????? x ??????, ????????? ??????????????? ???
13
RegExp ? PHP
  • ???????????? 2 ????????? POSIX ? PCRE (version
    gt4. ???)
  • POSIX - ?????? Apache ? mod_rewrite ? MySQL ?
    ????? ????????
  • PCRE - ??????? perl.

14
RegExp ? PHP
  • ?????? ????????????? ? PHP -
  • if (ereg("a-zA-Z0-9", text)) ...
  • ( ???? ?????? ?????????, ???? ?????? ???????,
    ???? ????? )
  • ?????? ??????????? (??????????? ? ?????????? -
    ???) ??????????? ????????
  • ?????? ????????????? ??????
  • if (ereg("lttaggt(a-zA-Z0-9)lt/taggt",
    text)) ...
  • (?? ?? ????? ???? ?????? ???? )

15
Subpatterns ????????? ???????
  • ??? ??????? ????????? ????????
  • ??? ?????? ?????? ?????????? ?????? ??? ?????????
    ?? ? ??????????.
  • ereg_replace("lta href(gt)gtltlt/agt", "\\0
    \\1", text)

16
????????? ?????????? ?????????
???????? ??????????
. (?????) ????? ????????? ??????.
(??????) ?????? ??????????????????, ??????????? ? ?????? ??????.
(???? ???????) ?????? ??????????????????, ??????????? ? ????? ??????.
A ????? A ? ??????? ????????.
a ????? a ? ?????? ????????.
\d ????????? ?????.
\D ????????? ??????, ?? ?????????? ??????.
\w ????? ????????? ?????-????????? ??????, ???? ???????? - ??????? alnum.
A-E ????? ????? ?? A, B, C, D ??? E ? ??????? ????????.
A-E ????? ??????, ????? ????? ?? A, B, C, D ??? E ? ??????? ????????.
17
????????? ?????????? ????????? (???????????)
???????? ??????????
X? ???? ??? ?? ????? ????????? ????? X.
X ???? ??? ????? ????????? ????? X.
X ???? ??? ????? ????????? ????? X.
Xn ????? n ????????? ???? X.
Xn,m ?? ????? n ? ?? ????? m ????????? ???? X. ???? ???????? m, ?? ???????? ???????? ??? ??????? n ????????? ???? X.
(abcdef) ?? ????? ????? ?????????????????? abc, def, abc ? def ????? ????????? ???????????.
18
?????? ? ????????? ????????
POSIX ????? ??????? ????????
upper A-Z ??????? ???????? ????????
lower a-z ??????? ??????? ????????
alpha A-Za-z ??????? ???????? ? ??????? ????????
alnum A-Za-z0-9 ?????, ??????? ???????? ? ??????? ????????
digit 0-9 ?????
xdigit 0-9A-Fa-f ????????????????? ?????
punct .,!? ????? ??????????
blank \t ?????? ? TAB
space \t\n\r\f\v ??????? ????????
cntrl ??????? ??????????
graph \t\n\r\f\v ??????? ??????
print \t\n\r\f\v ??????? ?????? ? ??????? ???????
19
?????? ?????????
  • ??????? ?????????
  • ?????? ?????????
  • ????????(???????????) ?????????

?????? ??????? ????????
?
? ?? ?
?
n, n,? n,
20
??????????
  • NFA (Nondeterministic Finite State Machine
    ??????????????????? ???????? ????????)
  • DFA (Deterministic Finite-state Automaton
    ????????????????? ???????? ????????)

21
GREP
  • ??????? ????????? ?????? (search globally for
    lines matching the regular expression, and print
    them)
  • ??????? ?? ????? ??????, ?????????? ?????????
    ??????????? ?????????, ? ??????? ??, ???? ?????
    ?? ??????? ??????????? ??????
  • ?????????? ???? ??????? ??? ???????????? ???????
    UNIX

22
??????????? GREP
  • egrep (? ?????????? ??????????? ??????????
    ?????????)
  • grep E
  • fgrep (?????????? ??????? ()\ ?????????)
  • grep -F
  • rgrep (? ?????????? ??????????? ???????)
  • grep -r

23
????????? GREP
  • grep '?????????? ?????????' '????
  • grep -E '(batBatcatCat)' heroes.txt
  • grep -i -E '(batcat)' heroes.txt
  • cat '????' grep '?????????? ?????????
  • cat heroes.txt grep -E 'bcBCat

24
??????? ??? GREP
  • ????????????
  • grep --color ta-z midsummer
  • ??????????? ??????????
  • grep o A-Za-z midsummer
  • ?????????? ??? ?????????
  • grep -E 'bcBCat' heroes.txt
  • grep -E '(batBatcatCat)' heroes.txt

25
????????? ???????? sed
  • sed -n -e script -f sfile files
  • ??????? ??????????????
  • addr , addr cmd args

26
??????? ?????????????? sed
  • " addr , addr " - ?????? ?????, ?????????
    ?????? (""), ?????????? ?????????
  • "\" ???????????? ? ????????????? ???????? ???
    ????????????? ??????????? ??????.
  • "." ????????? ? ????? ????????.
  • ???? ?????? ?? ??????? - ??????????????? ???
    ??????? ??????.
  • ???? ???? ?????, ?? ?????????? ???????????
    ??????.
  • ???? ?????? ??? ??????, ?????????? ?????? ?
    ???????? ?????????.
  • "!cmd" ??????????? ??????? "cmd", ??? ?????,
    ??????? ?? ???? ??????? ?? ???????.

27
??????? ?????????????? sed
  • (1)a\ text
  • (2)b label
  • (2)c\ text
  • (2)d
  • (1)i\ text
  • (2)p
  • (1)q
  • (2)r rfile
  • (2)y/str1/str2/

28
?????? ????????????? sed
  • who sed '2a\
  • ????? ??????
  • '

29
????????? ???????
  • root tty1 Mar 13 1723
  • mas tty2 Mar 13 1850
  • ????? ??????
  • sae tty6 Mar 13 1724
  • sae tty5 Mar 13 1724

30
?????? 1. ????? ? ????????
31
?????? 2. Username
32
?????? 3. ??????
33
?????? 4. XML tag
34
?????? 5. Email
35
?????? 6. URL
36
?????? 6. IP ?????
37
?????? ?????????
  • xyz
  • ????????? \(????\)
  • ????? ???????? ?????? ? ?????, ??? ???????
    ????????? ???? ?? ??????
  • ????? ???????? ?????? - ? ?????, ??? ???????
    ????????? ???? ?????? ??? ?????????. ????????
  • ?????? DNS-????? -0-9a-zA-Z.
  • ????? ??????, ????? ?????? ? ????? -0-9
  • ????? ???????? ?????? ??? ? ?????
  • ab ????????????? , , a ??? b
  • reg_exp
Write a Comment
User Comments (0)
About PowerShow.com