Differences between text search tools grep, egrep, and fgrep

Source: Internet
Author: User
Tags egrep

1. grep

1. Purpose:The text search tool performs a row-by-row search on the target file based on the user-specified text pattern to display the row content that can be matched by the pattern.

2. Command Format:Grep [Option] 'patten 'files...

2.1 explanation of common options

2.1.1 single file search:

-N: displays the row number of the matched row (n + other options are used below to show clearly matched rows)

-V: reverse matching (displaying non-matching rows)-> it is often used to filter out irrelevant information and increase the readability of the displayed information.

650) This. width = 650; "style =" background-image: none; border-right-0px; padding-left: 0px; padding-Right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px "Title =" 00000f} 8B} vegjp @ 9f3h4k0wf "border =" 0 "alt =" 00000f} 8B} vegjp @ 9f3h4k0wf "src =" http://img1.51cto.com/attachment/201410/13/4479540_1413219779HFrj.jpg "width =" 354 "height = "204"/> ※the first [5] indicates that the first row is matched.

-O: only the strings matched by the pattern in the row are displayed, rather than the whole row.

650) This. width = 650; "style =" background-image: none; border-right-0px; padding-left: 0px; padding-Right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px "Title =" X {p_niw65wxoh7d (A [[c_p3 "border =" 0 "alt =" X {p_niw65wxoh7d (A [[c_p3 "src =" http://img1.51cto.com/attachment/201410/13/4479540_1413219780UpCK.jpg "width =" 349 "Height =" 146 "/> ※see, the first line has two matched items. But the fourth line is not matched in upper case. What should I do? Next, let's look at it.

-I: case-insensitive characters.

650) This. width = 650; "style =" background-image: none; border-right-0px; margin: 0px; padding-left: 0px; padding-Right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px "Title =" image "border =" 0 "alt =" image "src =" http://img1.51cto.com/attachment/201410/13/4479540_1413219780iMus.png "width =" 352 "Height =" 184 "/> ※※all the hello all are matched.

-E: supports extended regular expressions. (This table is not used for the time being. We will talk about it together when we talk about regular expressions below) = egrep

2.1.2 multi-file search

If there is no option for multi-file search, the file corresponding to the matching row is displayed by default after the matching row is found.

650) This. width = 650; "style =" background-image: none; border-right-0px; margin: 0px; padding-left: 0px; padding-Right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px "Title =" {% 1' efbly7dcqk7xd7cax ~ 6 "border =" 0 "alt =" {% 1 'efbly7dcqk7xd7cax ~ 6 "src =" http://img1.51cto.com/attachment/201410/13/4479540_1413219782j3o9.jpg "width =" 392 "Height =" 202 "/> ※[:] before is the corresponding file name, if do not want to show it?

-H: When querying multiple files, the file name is not displayed.

650) This. width = 650; "style =" background-image: none; border-right-0px; margin: 0px; padding-left: 0px; padding-Right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px "Title =" 18cj _ @ QW (63 MB $ h) tzg8} XC "border =" 0 "alt =" 18cj _ @ QW (63 MB $ H) tzg8} XC "src =" http://img1.51cto.com/attachment/201410/13/4479540_1413219783WQIj.jpg "width =" 409 "Height =" 208 "/> ※it seems more confusing... .

-L (Ai Lu): Only names containing matching characters are output when multiple files are queried.

650) This. width = 650; "style =" background-image: none; border-right-0px; margin: 0px; padding-left: 0px; padding-Right: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px "Title =" 1E] (] I (j2oe1 ~ Z9lxj] Er} 2 "border =" 0 "alt =" 1E] (] I (j2oe1 ~ Z9lxj] Er} 2 "src =" http://img1.51cto.com/attachment/201410/13/4479540_14132197842Szn.jpg "width =" 406 "Height =" 87 "/>

2.2 explanation of text mode (regular expression)

In the examples listed above, the searched text is all strings. Of course, we can also use regular expressions to search.

2.2.1 basic Regular Expressions

? Character matching

".": Any single character

(To be continued)

Differences between text search tools grep, egrep, and fgrep

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.