RHCE7--using regular expressions with Gerp

Source: Internet
Author: User

Regular expressions often contain shell metacharacters (such as s, *, etc.), and it is recommended to enclose regular expressions on merriness using single quotation marks (")

1. Line positioning symbols

Beginning of position symbol ^ and line tail Locator $

#找出以s开头的行:

' ^s ' /etc/passwd


#找出以h结尾的行:

' h$ ' /etc/passwd


2. Word locator (positioning words)

#找出包含以s开头的单词的行

' \<s ' /etc/passwd

#找出包含以h结尾的单词的行

' h\> ' /etc/passwd

In the same file, the number of rows found by word positioning is greater than the number of rows found at the beginning or end of the line:

' \<s ' /etc/passwd |WC-lnotoginseng'^s' /etc/passwd |WC-  L5

3.grep Common Options

Options Function

-I.

Use the provided regular expression: But not case-sensitive
-V Show only rows that do not contain regular expression matches
-R A data search that recursively matches regular expressions is applied to a set of files or directories
-A <number> Shows the number of rows after a regular expression match
b <number> Shows the number of rows before a regular expression match
-E If multiple-e options are used, multiple regular expressions can be provided and used with logical OR

RHCE7--using regular expressions with Gerp

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.