Summary of common usage of grep in Linux

Source: Internet
Author: User

grep is the command of the Linux Chinese editing class to select the desired text content


Main format: grep [option] "PATTERN" FILENAME

Option:-I ignores case

-O displays only the characters that match

-V Reverse display (shows rows not matched to)

--color to display matching characters in color notation


"PATTERN": Supports RegExp (regular expression)

1, character matching:

. : Matches one character

[]: Character matching interval example: [A-z]

[^]: Character matching reverse interval example: [^a-z]

2. Number of character matches

*: Any number of common usage:. *: Any number of characters

\?: 0 or 1 times

\{m,n\}: At least m times, up to N times

\{1,\} at least 1 times

\{0,3\} 0-3 plays

3, anchor character

^: Anchoring the beginning of the line

$: Anchor Line End

\<: Anchor Word first

\>: Anchor ending

4. Grouping

\(.. \): Group Overall match for example: \ (ab\): With AB as a whole

Latter references: \1 \2 \3 characters in a group

\1: Represents a group in a forward reference to the first (to corresponding)

\2: Represents a grouping in a second "(to corresponding") reference


This article is from the "7792395" blog, please be sure to keep this source http://7802395.blog.51cto.com/7792395/1616736

Summary of common usage of grep in Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.