Linux Find string command grep

Source: Internet
Author: User

The Linux grep command is used to find strings that match the criteria in a file.

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.

Grammar

grep [-abcefghhillnqrsvvwxy][-a< Show Columns >][-B< show columns >][-C< Show columns >][-d< action >][-e< template style >][-f < template >][--help][template style [file or directory ...]

Parameters :

-A or--text do not ignore binary data. -A< show columns > or--after-context=< display columns >in addition to displaying the column that conforms to the template style, displays the contents after that column. -B or--byte-offset indicates the bit number of the first character of the column before displaying the column that conforms to the template style. -B< show columns > or--before-context=< display columns >in addition to displaying the column that conforms to the template style, displays the contents before the column. -C or--count calculates the number of columns that conform to the template style. -C< show columns > or--context=< display columns > or-< display columns >in addition to displaying the column that conforms to the template style, the content before the column is displayed. -D< perform actions > or--directories=< Actions >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< template styles > or--regexp=< template styles >specifies the string to be a template style for finding the contents of a file. -E or--extended-regexp uses the template style as an extended normal notation. -F< template file > or--file=< template 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-regexp treats the template style as a list of fixed strings. -G or--basic-regexp use the template style as normal notation. -H or--no-filename does not indicate the file name that the column belongs to until it displays the column that conforms to the template style. -H or--with-filename indicates the file name that the column belongs to before it displays the column that conforms to the template style. -I or--ignore-case ignores the difference in the 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 that do not conform to the specified template style. -N or--line-number indicates the column number of the column before displaying the column that conforms to the template style. -Q or--quiet or--silent does not display any information. -R or--recursive the effect of this parameter and specifies"-D recurse"parameters are the same. -S or--no-messages does not display an error message. -V or--revert-match reverse lookup. -V or--version displays version information. -W or--WORD-REGEXP displays only the columns that match the whole word. -X or--LINE-REGEXP displays only columns that are eligible for all columns. -Y the effect of this parameter and the specified"-I."parameters are the same. --help online Help. 

Instance

1. In the current directory, look for the file with the word "test" in the file that contains the "test" string, and print out the line of the string. At this point, you can use the following command:

2. Recursively find files that match your criteria. For example, to find a file that contains the string "Update" in all files under the specified directory/ETC/ACPI and its subdirectories (if one exists), and prints out the contents of the line containing the string, the command used is:

3, reverse lookup. The previous examples were to find and print out qualifying rows, and the "-V" parameter could print out the contents of a non-conforming line.

Find the line in the file that contains test in the filename that does not contain test, at which point the command used is:

Grep-v test*

Transferred from: http://www.runoob.com/linux/linux-comm-grep.html

Linux Find string command grep (GO)

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.