Shell script grep command

Three Musketeers: grep sed awk

  grep: text line filtering tools

  sed: text line editor (stream editor)

  awk: report generator, an output formatter

grep contains three commands:

  grep egrep fgrep. They are used for pattern matching row

  egrep: = grep -E uses extended regular expressions to match

  fgrep = fast grep only files matching a wildcard

  * Grep default use regular expressions to match text

grep usage:

  grep [option] …PATTERN [filename]

grep common options:

-E

Supports extended regular expressions

-P

Using perl regular expression language search engine (each language)

-I

Ignore case

-O

Only output matching content (the default output is a row)

-v

Anti-election

--color=auto

Syntax coloring

-n

Show Line Numbers

pattern-- regular expression:  

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

  1. Character Matches:

    Any of a character?

    [] Any one of the characters in the range

    Any one character [^] outside the range

    字符类:[:digit:]  [:alnum:]  [:alpha:]  [:lower:] [:upper:] [:space:] [:punct:]

  2. The number of matches

    * Match preceding character zero to n times  

    \? Matches the preceding character zero to 1

    Matches the preceding character + 1 to n times

    \ {M \} matches foregoing character m times

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

    \ {0, n \} Matches the preceding character 0 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. Packet

    abc * abccccc abc we want as a whole

    \ (\) Example: \ (abc \) * abcabcabc abcccc

    ** grouping characteristics: By default, linux packet will specify the variable representation variables ,, \ 1 \ 2 \ 3 ............

    (((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3})

Guess you like

Origin www.cnblogs.com/shy13138/p/11363812.html