Linux study notes -- grep command (search string command)

Source: Internet
Author: User

Linux study notes -- grep command (search string command)

Grep, which is used to search for strings that match the conditions in the file.

1. Command Format:

Grep [Option] string file name...

2. Common options:

"Grep-c" counts the number of rows matching the 'string' content. (C Indicates count.) "grep-I" ignores the case sensitivity. (I indicates ignore) "grep-l" prints a list of files matching the 'string' content. "Grep-n" prints the row number before the matched row. (N indicates line number) "grep-v" only displays unmatched rows. (V indicates reverse) "grep-w" full-character match search. (W indicates word regexp) "grep-A 4" outputs the rows matching the 'string' content and the last four rows. "Grep-B 4" outputs the rows matching the 'string' content and the first four rows. "Grep-C 4" outputs the rows matching the 'string' content and the first and fourth rows.

3. Common examples:

1) Find the row with 'exception' in the stdout1.log file.

2) Search for the number of rows with 'exception' in the stdout1.log file.

3) In the stdout1.log file, find the row with 'exception' and display the row number.

<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxwcmUgY2xhc3M9 "brush: SQL;"> 4) Find the row with 'exception' in the stdout1.log file, ignore the case and display the row number.

5) Find the row with 'exception' in the stdout1.log and stdout2.log files.

6) print out a list of files matching the 'string' content.

7) Search for lines with 'exception' and 'error' in the stdout1.log file.

8) in the stdout1.log file, find the rows with 'error' and the information of the first and fourth rows.

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.