Linux Learning Note--grep command (search string command)

Source: Internet
Author: User

grep, which finds the meaning of a string, is to match a qualifying string in a file.

1. Command format:

...

2. Common options:

"Grep-c"Statistics Match to' String 'The number of rows for the content. (c is the meaning of count)"Grep-i"ignores case differences. (I for the meaning of ignore)"Grep-l"Print out matches to' String 'The list of documents for the content."Grep-n"Prints the line number in front of the matching line. (N is Line  Numbermeaning)"Grep-v"Only rows that do not match are displayed. (V for the meaning of reverse)"Grep-w"Search with whole word matching. (W isWordThe meaning of RegExp)"Grep-a 4"Output matches to' String 'The contents of the line and after4Yes."Grep-b 4"Output matches to' String 'Line and front of content4Yes."Grep-c 4"Output matches to' String 'Lines of content and before and after4Yes.

3. Common examples:

1) 在stdout1.log文件中查找有‘exception‘的行。

2) 在stdout1.log文件中查找有‘exception‘的行的数目。

3) 在stdout1.log文件中查找有‘exception‘的行,并显示行号。

4) 在stdout1.log文件中查找有‘exception‘的行,忽略大小写并显示行号。

5) 在stdout1.log和stdout2.log文件中查找有‘exception‘的行。

6) 打印出匹配到‘字符串‘内容的文件清单。

7) 在stdout1.log文件中查找有‘exception‘和‘error‘的行。

8) 在stdout1.log文件中查找有‘error‘的行和前后4行的信息。

Linux Learning Note--grep command (search string 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.