Shell---grep command detailed

Source: Internet
Author: User

First, grep ----"Line filter Tool"

grep (Global search Regular expression (RE) and print out of the line, fully search regular expressions and Printing a line is a powerful text-search tool that can use regular expressions to search for text, find rows that contain certain strings, or a class of strings that conform to a pattern (pattern), and print the matching rows .

grep can be used for Shell scripting, because grep describes the status of the search by returning a status value, or 0 if the template search succeeds, or 1 if the search is unsuccessful, or 2 if the searched file does not exist. We can use these return values to do some automated text processing work.

GREP-E: Matching in extended mode

Egrep: Regular Matching tool

Second, grep command induction

Syntax :grep [-abcefghhillnqrsvvwxy][-a][-b][-c] [-d][-e][-f][--help][--color] [Template mode] [ File or directory ...]

    Additional Information:
The grep directive is used to find the file that contains the specified template style, and if the contents of a file are found to conform to the specified template style, the preset grep command displays the column containing the template style. If no file name is specified, or if the given file name is "-", the grep instruction reads the data from the standard input device.

Parameters:

-A or--textdo not omit binary data.
-A or--after-context=displays the column that conforms to the template style + the contents after the column .
- B or--byte-offset before displaying the column that conforms to the template style, mark the digit number of the first character in the column .
- B or--before-context=Displays the column that conforms to the template style + what precedes the column.
- C or--countcalculates the number of columns that conform to the template style.
-C or--context= or-displays the column that conforms to the template style + the contents before and after the column .
- D or--directories=You must use this parameter when you specify that you want to find a directory instead of a file, otherwise the GREP directive returns information and stops the action.
- e or--regexp= Specifies the string to be a template style for finding the contents of a file.
- e or--extended-regexpUse the template style as an extended Normal representation . Display content that conforms to the template mode
- F or--file= Specifies the template file whose contents contain one or more template styles that let grep find the contents of the file that match the template criteria, in the form of a template style for each column.
- F or--fixed-regexptreats the template style as a list of fixed strings .
- G or--basic-regexpuse the template style as a normal notation .
- h or--no-filenameThe name of the file to which the column belongs is not marked until the column that conforms to the template style is displayed.
- h or--with-filenameindicates the name of the file to which the column belongs before displaying the column that conforms to the template style.
- I. or--ignore-case ignores the difference in case of characters.
- L or--file-with-matches lists file names that match the file contents to the specified template style.
- L or--files-without-match lists file names for file contents that do not conform to the specified template style.
- N or--line-numberbefore displaying the column that conforms to the template style, mark the column number of the column .
- Q or--quiet or--silent does not display any information .
- R or--recursiveThe effect of this parameter is the same as specifying the "-D recurse" parameter.
- s or--no-messages No error message is displayed .
- V or--revert-match Reverse Lookup . Show culling of other content that conforms to template mode
- V or--version Displays version information .
- W or--word-regexp only columns that match the whole word are displayed .
- x or--line-regexp displays only the columns that are eligible for all columns .
- yThe effect of this parameter is the same as specifying the " -i" parameter. Ignore Case

--help     online Help.

--color=auto     can display the keyword portion of the found color .


C. grep Command Example

Common commands:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/83/43/wKiom1duTRah3C0wAAEI959LBIM959.jpg "title=" G2-0.jpg "alt=" Wkiom1dutrah3c0waaei959lbim959.jpg "/>


650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/83/43/wKioL1duTtqByvbSAAC1NZeNvJs271.jpg "title=" G2-1.jpg "alt=" Wkiol1duttqbyvbsaac1nzenvjs271.jpg "/>


Summary: grep command to find a match is more convenient, but its parameters are numerous, so need to pay attention to more practice, familiar with the command parameters and the use of collocation.


This article is from the "Flower Open Shore" blog, please be sure to keep this source http://zxtong.blog.51cto.com/10697148/1792869

Shell---grep command 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.