Grep command usage

Source: Internet
Author: User
Tags egrep

Grep command usage
1. grep family

Grep: Global search Regular Expression (RE) and Print out the line
The grep family includes grep, egrep, and fgrep, egrep, and fgrep.
Egrep is an extension of grep and supports more metacharacters, equivalent to grep-E.
Fgrep is fixed grep, or fast grep. It does not recognize any regular expression. All characters represent itself, which is equivalent to grep-F.

2. Meta Character Set supported by grep

Supports the basic metacharacters and additional metacharacters of regular expressions.
In addition, the grep extension metacharacters are also supported, mainly including:

W text and number characters, that is, the [A-Za-z0-9] Lw * e matches an L character, followed by 0 or more characters or numbers, followed by e
W non-text and numeric characters, I .e. [^ A-Za-z0-9], opposite to w
+ Match one or more previous characters [a-z] \ + ove match a lower-case character and followed by ove.
? Match 0 or 1 Previous character
A | B | c matches a, B, or c hate | love

3. egrep

In GNU grep (grep-G), if a backslash is added before the character, the character is translated into an extended regular expression, just like egrep and grep-E.
$ Egrep's (h | u) 'datafile
Or
$ Grep-E's (h | u) 'datafile
Or
$ Grep's (h | u) 'datafile

Exception: The word anchoring symbol <>. A backslash must be added to any grep.
$ Grep '<north> 'datafile
$ Grep-E '<north> 'datafile
$ Egrep '<north> 'datafile
$ Grep-w 'North 'datafile

4. grep options

-C only displays the number of matched rows
-I case-insensitive
-N print the row number
-S silent operation, no error message displayed
-Q: silent work, no search results displayed
-V only displays unmatched rows
-W is equivalent to <>

5. Example

1) Search for strings in one or more files
# Grep "hello, world"./hello1.txt./hello2.txt

2) Search for Summary information
# ../Gcc-4.4.1/contrib/test_summary | grep-A7 Summary
Search for rows with Summary and display the last seven rows of the row. This method is used to display the summary information in some test results.

3) recursive Directory Search
# Grep-R 'typedef struct page {'./

4) flip the search results
# Grep-v deinstall // search for rows that do not contain deinstall

Grep uses concise and Regular Expressions

Shell programming in Linux -- basic use of the grep command

Grep command details and related examples

Linux basic commands-grep

Set grep to highlight matching items

Linux grep command learning and summary

Example of 14 grep commands

This article permanently updates the link address:

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.