Learning shell fourth day

A, grep program
  1, the text processing under linux trio - Sed awk grep
    grep: line of text filtering tools
    sed: text line editor (stream editor)
    awk: report generator (do formatting text output)

 

  2, grep
    contains three commands: grep egrep fgrep, they are used for line mode (pattern) matches the
    egrep = grep -E // use extended regular expression matching
    fgrep = fast grep // use files wildcards matching
    * grep default text using regular expressions to match *

  3, grep usage:
    grep [the Option] ... the PATTERN [filename]

 

 

 

  4, grep's common option - the Option
    -E supports the use of extended regular expression (ERE) (regexp)
    -P use perl regular expression language search engine (every language of regular expression engine is not the same, even sed grep awk regexp engine used is not the same)
    -i ignore case
    -v anti-election
    -o output only content that matches (the default output is matched to the line)
    --color = Auto syntax coloring
    -n display line numbers
    -w word match fixing

 

 

 

Two, PATTERN-- regular expression
  functions: through some special characters to represent the contents of a class character, and then to the front of the command; if you use special characters meaning itself, we need to \ escape;

 

  Review: file wildcard (globbing)
    * [] [^]?

 

  1, character match
    . Any one character equivalent?
    [] Any one of the characters in the range
    [^] outside the range of any character
    character class: [: digit:] [: alnum:] [: alpha:] [: lower:] [: upper:] [: space:] [ : punct:]
  2, the number of match
    * matches the preceding character zero to n times
    ? Matches the preceding character zero to 1
    + Matches the preceding character 1 to 0 views
      [ABC] + abbbbcccc
    \ {m \} matches the preceding character m times
      A \ {. 7 \} AAAAAAA
    \ {m, n-\} Match in front of the character m to n times
    \ {0, n \} matches the preceding character zero [0 to n times or not? }
    \ {M, \} the preceding matching character least m

 

  3, the position of the anchor

 

    ^ Anchors the first line
    $ end of line anchor
    \ b anchor and anchor the first word endings
    \> anchor suffix
    \ <anchoring the first word
    <\ root \> rooter

 


  4, grouping
    abc * abcccc abc we want as a whole
    \ (\) Example: \ (abc \) * ABCABCABC abcccc
    ** grouping characteristics: Representation By default, Linux system will be designated as the grouping variable, variable \ 1 \twenty three …

 

    Example: \ (ab + \ (xy \) * \) wherein \ 1 = ab + \ (xy \) *, \ 2 = xy

Guess you like

Origin www.cnblogs.com/duyunlong123456/p/11360436.html