Shell --- The basic syntax of the grep command processing huge amounts of data

 grep command

  • One shell script Three Musketeers
  • grep scenarios: usually extracted line data

  • Syntax: grep [options] [content] [file]

    • -v the content negated extract

    • -n display line numbers to extract the contents of

    • -w exact match

    • -i ignore case

    • ^ Matches the beginning of the line

    • -E regular match

  • Regular grammar

Regular Expressions description example
\ Escape, the escape special characters, ignoring its special meaning A . b match ab, but it can not be escaped to match ajb ,. special significance
^ Match the beginning of the line ^ it is the beginning of the string match ^ Tux tux match starts with the line
$ Matching end of the line, $ end of the string is tux tux $ match to the end of the line
. Matches any single newline character \ n other than ab. match abc or bad, can not match abcd or abde, can only match a single character
[] Match any one character is included in the [characters] among coo [kl] matches cook or cool
[^] Matches any character other than character 123 45 not matching 1235,1236,1237 or 1234 may be
[-] With any one of the characters in the range [] is specified to be written is incremented [0-9] 1, 2 or 3, matches any of a number
? Before the match 1 or 0 times olou? r matches color or colour, can not match colouur
+ Before the match 1 or more times sa-6 + match sa-6, sa-666, does not match sa-
* Before matches zero or more times co * l matches cl, col, cool, coool etc.
() Matching expression, create a substring for matching ma (tri)? max match or maxtrix
{n} N times before matching items, n being a positive integer is 0 can be [0-9] {3} matches any three-digit number can be expanded to 0-9 [0-9]
{n,} Prior to entry need to match at least n times [0-9] {2} matches any two-digit or more bits
{n,m} Before the specified items matching at least n times, matching up m times, n <= m [0-9] {2,5} from two digits to match any of a five-digit number between
| Alternating match | any of both sides ab & (C | D) match abc or abd

 

  • Common rules
description
* All characters
[Az] lowercase
[AZ] uppercase letters
[AZ] lowercase and uppercase letters
[0-9] Digital

Guess you like

Origin www.cnblogs.com/chusiyong/p/11273856.html