Detailed introduction to Linux grep commands

Source: Internet
Author: User

Linux has become more and more popular among computer users. As a result, many users may encounter Linux grep commands when learning linux. Here we will introduce how to solve the Linux grep command problems, I will share it with you here.

Grep
Function Description: Find the matching strings in the file.
Syntax: grep [­ abcEFGhHilLnqrsvVwxy] [­ A] [­ B] [­ C] [­ d]
[­ E template style] [­ f template file] [­ help] [template style] [file or directory...]
Note: The grep command is used to find files whose content contains the specified template style.
For the specified template style, the default grep command will display the column containing the template style. If no text is specified
The device name, or the given file name is "­". Then, the grep command reads data from the standard input device.

Parameters:
-E, -- extended-regexp PATTERN is considered as an extended regular expression.
-F, -- fixed-stringsPATTERN is a set of strings opened with linefeeds.
-G, -- basic-regexp PATTERN is considered as a basic regular expression.
-P, -- perl-regexp PATTERN is treated as a regular expression of Perl.
-E, -- regexp = PATTERN treats PATTERN as a regular expression.
-F, -- file = FILE get PATTERN from FILE
-I, -- ignor-case ignore case-insensitive commands
-W, -- word-regexp forces PATTERN to match only the complete word
-X, -- line-regexp forces PATTERN to match only the complete row
-Z, -- null-data row ends with zero bytes instead of line breaks

Miscellaneous:
-S, -- no-messages Do Not Display error messages
-V, -- invert-match: Select unmatched rows
-V, -- version: print the version information and exit
-- Help: displays the help and exits.
-- If possible, mmap uses a memory image as the input.

Output Control:
-M, -- max-count = the number of times the job stops after the specified number of times is matched.
-B, -- byte-offset: the output matches the row and displays the byte offset.
-N, -- line-number: Output matched rows and display row numbers
-- Line-buffered flush output in each row
-H, -- with-filename output each matching file name
-H, -- no-filename output does not display prefix file names
-- Label = specifies the <flag> as the name of the standard output file.
-O, -- only-matching only displays rows that can match the pattern
-Q, -- quiet, -- silent does not display all normal output
-- Binary-files = type. Assume that the parameter is a specified <type> binary file,
<Type> it can be "binary", "text", or "without-match"
-A, -- text is equivalent to -- binary-files = text
-I is equivalent to -- binary-files = without-match
-D, -- directories = specifies the <behavior> method of the directory to be processed
<Behavior> it can be "read", "recurse", or "skip"
-D, -- devices = specifies the action to process device files, MPs queue files, and socket files. <action method>
<Behavior> it can be "read" or "skip"
-R,-r, -- recursive is equivalent to -- directories = recurse
-- Include = the file with the specified <mode> pattern matching will be checked
-- Exclude = the file whose mode matches the specified <mode> will be skipped.
-- Exclude-from = the file matches the specified <File> pattern. The file will be skipped.
-L, -- files-without-match only print the <File> name that does not match
-L, -- files-with-matches: only the matched <File> name is printed.
-C, -- count: only prints the number of matched rows for each <File>
-Z, -- null Output "0" bytes after <File Name> name

Context control:
-B, -- before-context = NUM: content of the <NUM> row before printing
-A, -- after-context = NUM content of the <NUM> row after printing
-C, -- context = NUM print the output content of the <NUM> row
-NUM and -- context = NUM are the same.
-- Color [= WHEN],
-- Color [= WHEN] uses a flag to distinguish matching strings.
WHEN can be "always", "never", or "auto ".
-U, -- binary does not remove carriage return characters at the <EOL> end of MSDOS-style files <CR>
-U, -- unix-byte-offsets report offset if <CR> carriage return does not exist

"Egrep" indicates "grep-E" and "fgrep" indicates "grep-F ".
If <File> is not specified, or <File> is-, it is read from the standard input. If
If the number of specified <File> is less than 2, The-h option is available. Exit status 0 indicates matching,
1 indicates no matching, 2 indicates an error.

I hope you will learn about the Linux grep command.

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.