The use of grep egrep fgrep and regular expressions in Linux systems

Source: Internet
Author: User
Tags regular expression egrep

First, grep, egrep, Fgrep command

In this paper, we mainly introduce the basic parameters and usage formats and methods of the Egrep fgrep commands and regular expressions under the Linux system. (Note: The FG represents an example in the text)

1.1, the basic definition:

grep (Global search regular RE) and print out of the line, a comprehensive search for regular expressions and print out rows) is a powerful text search tool that can only use basic regular expressions to search for text and print matching rows.

grep is a very common and often used command whose main function is to compare string data and then print the strings that match the needs of the user, but the idea is that grep searches for a string in the data, which is filtered in whole rows.

The Egrep command is equivalent to GREP-E, which enables you to use extended regular expressions to search for text and print strings that match the user's needs.

The Fgrep command is equivalent to Grep-f, which uses a fixed string to search for text, but does not support regular expression references, so this command executes the fastest.

1.2. Basic usage of command

grep [option] ' Search string ' filename

grep Common options:

-A: Searching for data in a binary file as a text file

FG: Search for rows containing RC strings within/etc/inittab

Grep-a ' RC '/etc/inittab

-C: Calculates the number of ' search strings ' found

-I: Ignore case

-V: Reverse lookup, which shows the line without the ' search string ' content

-O: Displays only strings matched by pattern

-N: Output line number

--colour (color): Colors display

-A: Displays the following n lines that match to the character Funa

-B: Show the front n rows that match to the character Funa

-C: Display the front and back n rows that match to the character Funa

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.