Linux egrep file content search tool and extended regular expression detailed

Source: Internet
Author: User
Tags egrep

Linux egrep file content search tool and extended regular expression detailed

egrep Command : Search for text based on patterns (matching criteria for text characters and extended Regular expression meta-character combinations)

and displays the line of text that conforms to the pattern.

Format: egrep [option] Match condition text name

egrep equals Grep-e .

Option:-I: Ignore case

-V: Show rows that are not matched by the pattern

-O: Displays only strings that are matched by the pattern

--color: Search out files High brightness display

-A: Matches the next few lines of the specified line

-B: Matches the last few rows of the specified row

-C: matches the upper and lower lines of the specified row

Regular Expressions : Regular expression, abbreviated RegExp

Meta characters :

.: Matches any single character

[]: matches any single character within the specified range

[^]: matches any single character outside the specified range

For example: special character set: [:d igit:], [: Lower:], [: Upper:], [:p UNCT:], [: Space:], [: Alpha:], [: Alnum:]

number of matches :

*: Matches any of its preceding characters any time

. *: Any character of any length

?: matches the preceding character 1 or 0 times, not like a basic regular expression, without adding \

{a,d}: matches the preceding character at least a, at most d times, not like a basic regular expression, without adding \

For example: {1} indicates that the preceding character matches 1 times

{0,6} means: The preceding character matches at least 0 times, up to 6 times

The position is locked or called anchored :

^: Locks the beginning of the line, any content after this character must appear at the beginning of the line

Example: Displaying lines beginning with R in the/etc/passwd file

egrep ' ^r '/etc/passwd

$: Locks the end of the line, any content that precedes this character must appear at the end of the row

Example: Show the line in the/etc/passwd file that the bash ends

egrep ' bash$ '/etc/passwd

^$: Indicates a blank line

\< or \b: Anchor word, any character following it must appear as the first word

\> or \b: anchors the ending, any character preceding it must appear as the tail of the word

Example: Displays a line in the/etc/passwd file that begins with Root and ends with the root word

egrep ' ^root\> '/etc/passwd

grouping : () is not like a basic regular expression, without adding \

For example: (MN) * indicates matching any MN combination character

Back to reference

\1: Refers to the first opening parenthesis and all the contents of the corresponding closing parenthesis

\2: Refers to the second opening parenthesis and all the contents of the corresponding closing parenthesis

\ n: references the nth opening parenthesis and all the contents of the corresponding closing parenthesis

or : |

To illustrate:

1.d|dog represents D and dog, not dog and dog.

2. Find the number between 1-255 in the/boot/grub/grub.conf file

Egrep--color ' \< ([1-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]) \> '/boot/grub/grub.conf

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7E/E8/wKiom1cMheHjDdXWAAG85_y-2OA660.jpg "title=" Egrep1.jpg "alt=" Wkiom1cmhehjddxwaag85_y-2oa660.jpg "/> 3. Find the IP address in the ifconfig command: Again,egrep equals grep-e

Ifconfig | grep--color-e ' (\< ([0-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]) \>\.) {3}\< ([0-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]) \> '

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/7E/E5/wKioL1cMh_azzWHJAAGNRTnZvvI126.jpg "title=" Egrep2.jpg "alt=" Wkiol1cmh_azzwhjaagnrtnzvvi126.jpg "/>

This article is from the "Xavier Willow" blog, please be sure to keep this source http://willow.blog.51cto.com/6574604/1762934

Linux egrep file content search tool and extended regular expression detailed

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.