-grep shell scripts and regular expressions

1, grep program:
    1) command: grep egrep fgrep, used to line mode (pattern manually write) matches the
       egrep = grep -E // use regular expressions to match    
       fgrep = fast grep // use files matching the wildcard
       * grep default text using regular expressions to match
    2) usage:
       grep [the option] ... the PATTERN [filename]
    3) common option (the option):
       -E supports the use of extended regular expression (regexp)
       -P with Perl regular expression search engine (each language regex engine is not the same, even grep, sed, regexp engine using awk is not the same)
       -c count statistics
       * -i ignore case
       * -v anti-election
       * -o output matching only the contents (the default output is matched to the line)
       --color = Auto grammar zhuose
       -n display line numbers
       -w match fixed word

2, PATTERN - regular expression
  functions: through some special characters to represent a class of characters, and then to the front of the command to execute; if you use special characters meaning in itself, it is necessary to use \ to escape
    file wildcards:
       *: any character of any length
       ? : Any character
    regular expression:
      1) character matches
          any character.
          | Or
          [] within the scope of any one character
          [^] outside the range of any character
          character class: [: digit:] [: alnum:] [: alpha] [: Space:] [: punct:]
      2) the number of matching
         \ * matches the previous character zero to n times
         \? Matches the previous character zero to 1
         \ + matches the previous character 1 to n times
         \ {m \} matches the previous character m times
         \ {m, n \} matches the previous character m to n times
             \ {0, n \} to match a character zero to n times
         \ {m \} matches previous character at least m
       3) position of the anchor
          ^ anchors the first line
          $ anchor end of a line
          \ b anchor the first word and anchor suffix
          \> anchor suffix
              \ <anchoring the first word \ <root \>
        4) grouping
           example \ (\): \ (abc \) * to abc as a whole
          * Grouping characteristics: By default, Linux packet will be assigned as a variable, the variable representation of \ 1 \ 2 \ 3 ..

Guess you like

Origin www.cnblogs.com/hmm01031007/p/11354542.html