grep usage summary

 

 

grep: global research regular and print out the line
-text search tool for
regular expressions:
basic regular expression:
extended regular expressions: egrep or grep -E
--color = Auto coloring
-i
-E like egrep
-P
-F
-o : only the matched string
-q: silent mode
-AN: displaying the matched row and next to the N rows,
-BN: N matching line from the previous row
-CN: context, N rows
substantially regular expression element character:
matching characters
. any single character
[] any single character within a matching range of
[: digit for:], [: Lower:], [: Upper:], [: Alpha:], [: alnum:]
[: Space: ]
number matches
* represents the previous character is repeated zero or more times, such as x * Y, then x represents 0 may be repeated once or more, repeating 0 times x indicates no
work to greedy
. # * indicates any character of any length
a. * y # a and y may have any intermediate character
\? # match 0 or 1, optional
\ # + at least 1, and more are not
\ {m \} # matches the preceding character repeated m times
practice :
Any character repeated 3 to 5 times, followed by a talk T:
grep "[[: Alpha:]] \ {3,5 \} T" / etc / the passwd
\ {0, n \} # 0 to n times
\ { m, \} times more #m

position anchor:
^ # line first anchor
^ the root is the root of the line #
$ # end of line anchor
practice:
identify the first line beginning with any letter, 1 to 3 appears after the letter t letter
grep '^ [[: alpha: ]] \ {1,3 \} t' / etc / passwd

 

 

Guess you like

Origin www.cnblogs.com/bright2029/p/11706880.html