Shell grep Command Daquan

Source: Internet
Author: User

grep: For fuzzy lookups, in standard input or file

  Format: grep [option parameter] ... PATTERN | FILE ...

Option parameter Description:

- E,--extended-regexp PATTERN is an extensible regular expression
-E,--regexp=pattern using PATTERN for matching operations
-F,--file=file gets the PATTERN from file
-I,--ignore-case ignore case
-W,--word-regexp mandatory PATTERN only matches words exactly
-X,--line-regexp force PATTERN to match only one line exactly
-Z,--null-data a 0-byte data row, but not a blank line
-C,--count only outputs the count of matching rows
-H,--no-filename does not display file names when querying multiple files
-H,--with-filename display file name
- N,--line-number matching line number
-O,--only-matching displays only matching content
-L,--files-with-matches only output filenames that contain matching characters
-L,--files-without-match only output mismatched filenames
-S,--no-messages does not display information that does not exist or matches the error
-V,--invert-match displays lines that do not contain matching text

"\<" and "\>" respectively mark the beginning and end of the word.
' ^ ': refers to a matching string at the beginning of the line
' $ ': refers to a matching string at the end of the line

grep  " \<kim " kimbo_test.sh A string starting with a #匹配 Kim,kimbo,kimko, etc. grep  " kim\> " kimbo_test.sh # Kim,mathkim,kobekim, etc. end of string grep " ^kim " kimbo_test.sh  #行首以kim开头 grep"kim$" kimbo_test.sh  #行尾以kim开头

Regular expressions

1. Match a single character

grep "\<1[0-9]" kimbo_test.sh #匹配以1开头的数字, the following character remains a number

2. Match repeating characters

grep "mf\{3\}" kimbo_test.sh #匹配以m开头, followed by three F content

3. Match 8-bit numeric date (YYYYMMDD)

grep '^[12]\{1\}[0-9]\{7\}$' kimbo_test.sh #强匹配 1 or 2 start date, such as 19901001,20171001, etc.

Shell grep Command Daquan

Related Article

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.