Linux grep and Regular Expressions (notes)

Source: Internet
Author: User

grep print lines matching a pattern printing line matching mode

grep This command is used to query and match a string in a text file

Example grep ' root '/etc/passwd This command is used to match the line that contains the root string in the passwd file

[[email protected] ~]# grep ' root '/etc/passwd
Root:x:0:0:root:/root:/bin/bash
Operator:x:11:0:operator:/root:/sbin/nologin


Parameters

-I ignores case (that is, the case will be matched to match the string)

--color This parameter is to highlight the matching string (user-friendly)

-V Reverse match, meaning that the string displayed is not matched to the row

-O displays only the matched string


Regular Expressions REGEXP (REGular expression)

Metacharacters

. The decimal point is used to denote a single character


Number of characters

* An asterisk matches any number of previous characters

. * These two symbols combine to represent any length of any character

? A question mark indicates that a previous character is matched one or 0 times

Linux grep and Regular Expressions (notes)

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.