- PowerPoint PPT Presentation

About This Presentation
Title:

Description:

4 ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 39
Provided by: cbbSjtuE
Category:
Tags:

less

Transcript and Presenter's Notes

Title:


1
??????????4????????
  • ??????????

2
????
  • ?????
  • ?????????????
  • ??????????(metacharacter)
  • VIM???
  • grep??
  • sed???
  • awk??

3
?????
  • ???????(regular expression, RE),
    ????????????,?????????????????????????????

4
VIM??
  • linux??????????

5
VIM???
  • ????????????
  • ?????????????i?
  • ?????????????a?
  • ?????????ESC?
  • ????
  • ?????????????wq
  • ?????????????q!
  • ??????????w
  • ??????????w filename

6
VIM????
  • ??????????????2?g
  • ?????????
  • ????????
  • ????????
  • ??100???100g

7
VIM????
  • ???????/pattern/??,????pattern??????????
  • ???????m,n/pattern/,????m???n???pattern?????

8
grep??
  • ????????

9
grep??
  • ?Global search regular expression (RE) and Print
    out the line???
  • ?????????,???????????,???????
  • ?????????????????,??????????,???????

10
grep??
  • grep option pattern input_files

11
??grep????
-? ????,???????????? grep -2 grep test.txt??????????2?
-c --count,?????????,???????
-f file ??????????
-i --ignore-case,?????
-q --quiet,????
-l ????????????
-l ????????????
-n --line-number,?????????
-s --silent,???????
-v --revert-match,????????
-w --word-regexp,???\lt?\gt??,?????????????
12
grep????????
?????? grep?????grep????
?????? grep?????grep????
. ????????????? gr.p??gr????????,??p??
??0???????? grep????0????????grep??
??????????? Ggrep????Grep?grep??
?????????????? A-FH-Zrep??????A-F?H-Z???????rep??
\( \) ?????? \(love\)?????love,?love????\1
\lt \gt ?????????????? \ltgrep???grep????? grep\gt???grep?????
x\5\, x\5,\,x\5,10\ x\5\, x\5,\,x\5,10\ x????5????????5?????????5-10?????
\w A-Za-z0-9 \WA-Za-z0-9 \w A-Za-z0-9 \WA-Za-z0-9 ??????(?)???????
\bgrep\b \bgrep\b ?????grep,???egrep?
13
????????????
  1. ls l grep a
  2. grep test d
  3. grep test aa bb cc
  4. grep a-z\5\ aa
  5. grep w\(es\)t.\1 aa
  6. grep n datafile
  7. grep 4 datafile
  8. grep 5\.. datafile
  9. grep \.5 datafile
  10. grep wesn datafile
  11. grep A-ZA-Z A-Z datafile
  12. grep ss datafile
  13. grep a-z\9\ datafile
  14. grep \lta-z.n\gt datafile

14
sed??
  • ????????

15
sed??
  • ???which sed????sed???
  • ???????????,????????????????
  • sed??????????????
  • ?????????,???
  • ??????????????????

16
sed??
  • ???????????????????,?????????????
  • ???????????????,?????????????????,??????????
  • sed option sed_command input_file
  • sed option f sed_script_file input_file
  • sed_script_file option input_file

17
sed?????
-n Quiet, ????????,??????
-e ?????????,????????????
-f ???sed????
18
sed???????
x ??,?????
x, y ??x-y????
xy ??x???,??y?
/pattern/ ?????????
x,y! ?????????x?y??
19
??sed????
p ????? sed n 2,3p test.txt sed n /movie/p temp.txt
?????? sed e /music/ temp.txt
a\ ??????????? sed /jack/ \a here add new linep temp.txt
i\ ??????????? sed 4 \i here add new linep temp.txt
d ????? sed /music/d temp.txt
n ????????????,??????? sed /movie/n temp2.txt temp.txt
c\ ?????????? sed 4 \c i like it temp.txt
s ??????????? sed s/source/okstr/add before /p temp.txt
r ??????????? sed /name/r temp2.txt temp.txt
w ????????? sed s/name/my /w temp2.txt temp.txt
20
????????????
sed s/\.//g temp.txt
sed e /abcd/d temp.txt
sed s/ / /g temp.txt
sed s///g temp.txt
sed s/\.//g temp.txt
sed //d temp.txt
sed s/.//g temp.txt
sed s/COL\(\)//g temp.txt
sed s/\///g temp.txt
21
AWK??
  • ????????

22
AWK??
  • Linux??awk?????awk?nawk?gawk,?????awk??/bin/awk,?
    ??gawk (GNU awk)
  • awk???
  • ?????????????????????
  • ???????????

23
awk???????
  1. awk option awk_script input_file1
    input_file2
  2. ?awk_script????????!/bin/awk f
    ????,???????????,???shell??????????awk_script???a
    wk_file input_file
  3. ???awk_script???????????,???awk f awk_file
    input_file(s)????

24
awk?????
  • ???????awk_cmd??,??awk_cmd?????NEWLINE??
  • awk_cmd??????awk_pattern actions
  • awk???????
  • awk BEGIN actions awk_pattern1 actions
    awk_patternN actions END actions
    input_file
  • ??BEGIN ?END??????

25
awk???????
  1. ????BEGIN??,?????actions
  2. ??????????,????????
  3. ???????????(FS/IFS)???????,???1,2,.,
    ?0???????
  4. ????????awk_pattern???,???????actions,????????????
    ???,????3,4,?????
  5. awk????????????,??????????????,???????????
  6. awk?????????,?????????,??????

26
awk_pattern???
  • ????? /regexp/
  • ???????? . ()
  • ?awk??????,?????????????
  • ???awk??????,????????0/1?
  • ??awk /\0\.0-90-9./ input_file
  • ????? ,gt, /regexp/,,
  • ??
  • awk 3 /d/ input_file
  • awk '(1 lt 10 ) (2 gt 10) print "ok"'
    input_file

27
actions???
  • actions??awk?????????
  • actions?????????????,?????????

28
awk??
  1. print 1 , 1
  2. printf?c???printf??
  3. next??????????
  4. nextfile????????????
  5. exitawk???????????END??,awk???END?actions

29
awk??
  • ????
  • awk 'BEGIN x1 y3 xy print "x" x "
    y" y
  • awk 'BEGIN x3 x2 yx2 print "x" x "
    y" y '
  • ??????
  • ? if (condition) then-body else else-body
  • ? while (condition) body
  • ? do body while (condition)
  • ? for (initialization condition increment)
    body ?C???for???????
  • ? break ??????for?while?do-while ??
  • ? continue ??for?while?do-while???body?????,????
    ?????????

30
awk????
  • ??????
  • NF??????????
  • NR??????????????
  • FNR???????????????
  • FILENAME??????????
  • ARGC???????,??????1
  • ARGIND???????ARGV????
  • ????1, 2, , NF, 0
  • ??????
  • FS ??????????(?????????)
  • OFS ??????????(?????)
  • OFMT ???????(??? .6g)
  • RS ?????????(???NEWLINE) ORS
    ?????????(???NEWLINE)
  • ARGV ??????? ENVIRON ??????????????,??????????
    ????????
  • ??cat /etc/passwd awk 'BEGIN FS"" print
    "User name "1,"UID "4'

31
awk?????
  • ????varnamevalue
  • ??????????????????,????????,????0?
  • ??awk 'awk_script' awkvar1value1 awkvar2value2
    .... input_file
  • ???awk_script??????????????????
  • ??????shell??,????awk 'awk_script'
    awkvar1shellvar1 awkvar2shellvar2 ....
    input_file

32
awk????
  • ????
  • int(x), sqrt(x), exp(x), log(x), sin(x), cos(x),
    atan2(y,x), rand(), srand(x), srand()
  • ?????
  • index(in, find), length(s), match(s, r),
    sprintf(), sub(p,r,t), gsub(p,r,t), substr(str,
    st, len), split(s,a,fs), tolower(str),
    toupper(str)
  • ????
  • close(filename), system(command)

33
awk?????
  • ???????
  • function fun_name(param_list) function_body
  • ??
  • awk print sum, SquareSum(1, 2) function
    SquareSum(x,y) sumxxyy return sum
    grade.txt

34
awk??
  • ??????
  • for ( element in array_name ) print
    array_nameelement
  • ??
  • awk BEGINprint split(123456789, mya, )
    for ( i in mya ) print myai

35
??awk?????
  • ? ????awk_script???????
  • ? ??awk_script?????????
  • ? ????????????,??????????
  • ? ?????????,?????????,?awk?????,???????
  • ? ???????,???????????????(??????)

36
  • 2) ?awk?,???????????????,?????????????????????????
    ?????namen
  • 3) ???BEGIN??????????????,?????awk??????????????
  • 4) awk??????????????????????????,?????????????????
    ????????????,????? awk_script??????(1?2?3...)??
    ????????????n(n???????NF)????
  • 5) ????????????,??????????????????????????????????
    awk??????????? \b ??? \t tab? \f ???? \ddd ????
    \n ?? \r ??? \c ?????????eg \\??????

37
awk?????printf
  • ? ?? printf ("???????", ????)
  • ? ?????????????,???????????????
  • ? ?????????????????????,??????????????????????????
    ??????????????
  • ? ????? -width.precfmt
    ????????????,????? - ??????????,???? width
    ????,?????????????,???? .prec
    prec?????,??????????????????,???? fmt
    ??????,???????????,?????
  • ? ???fmt c ASCII??, d ?? ,e ????????, f ???,?
    123.44 g ?awk???????????e?f ,o ????, s ???, x
    ?????
  • ? ??
  • echo "65" awk ' printf ("c\n",0) ' // ??? A
  • awk 'BEGINprintf ".4f\n",999' //??? 999.0000
  • awk 'BEGINprintf "2 number8.4f8.2f",999,888'
    // ??? 2

  • // number999.0000
    888.000

38
??
  • sed?????????
  • awk???????????
  • col1 col2 col3 col4
  • ???????????sed?awk????,???????????????perl/python?
    ???
  • ??C/C?????????????,??,??1-2??????????????,?????
    ??
Write a Comment
User Comments (0)
About PowerShow.com