Shell of the fourth day of school

grep with regular expression:

1, grep program

      There trio --grep sed awk text processing under linux

      grep: text line filtering tools

      sed: text line editor (stream editor)

      awk: report generator (do formatting text output)

  grep: contains three commands: grep egrep fgrep, they are used for pattern matching row

  egrep = gerp -E // use extended regular expression matching

  fgrep = fast grep // use files matching the wildcard

  * Grep default use regular expressions to match text

  grep usage:

        grep 【option】 ...  PATTERN【filename】

  grep common options --option

        -E support the use of extended regular expressions

        -P use perl regular expression language search engine (each language regex engine is not the same)

        -i ignore case

        -w word match fixing

        -v Invert Selection

        -o output only matched content

        --color = auto syntax coloring

        -n Display line numbers

     PATTERN-- regular expressions

        Role: through some special characters to represent a class character, and then to the front of the command to execute; if you use special characters meaning in itself, it is necessary \ to escape

        1, character match

              The representative of any one character corresponds to file a wildcard?

              [] Any one of the characters in the range

              Any one character [^] outside the range

              Character classes: [: digit:]
                     Any number, equivalent to 0-9
                    [: Lower]
                     any lowercase letter
                    [upper:]
                     any capital letters
                    [alpha:]
                     any case letters
                    [: alnum:]
                     any number or letter
                    [: blank :] |
                     horizontal whitespace
                    [: space:]
                     horizontal or vertical whitespace
                    [punct:]
                     punctuation
                     [Print:]
                      Printable characters
                     [: cntrl:]
                       the control (non-printing) characters
                     [: graph:]
                       graphic characters
                      [xdigit:]
                       hexadecimal characters

        2, matching the number of times *** match whitespace characters ^ [[: space:]] ***

              * Matches the preceding character zero to many times

              \? Matches the preceding character zero to 1

              + One character matches one thousand meters lesson plans to the n-th

              \ {M \} characters arranged in front of M times

              \ {M, n \} matches the character preceding to n times m

              \ {0, n \} matches the preceding character zero to n times

              \ {M, \} the preceding matching character least m

 

        3, the position of the anchor

              ^ Anchor of the line

              $ Anchored end of the line

              \ B anchor and anchor the first word endings

              \> Anchor suffix

              \ <Anchoring the first word

        4, group

            \ (\) Example: \ (abc \) * abcabc

            Grouping characteristics: By default, Linux system will be designated as the grouping variable, variable representation of \ 1 \ 2 \ 3 .....

Important points: interactive mass participation: read -p # // - t is wait a few seconds

  Examples: read -p ( "Please enter a thing:") filename

Guess you like

Origin www.cnblogs.com/zrxuexi/p/11353164.html