"Linux" uses grep to find content in a document

Source: Internet
Author: User

Sometimes, we need to find some content in the document, commonly used grep. It finds relevant content in the document and outputs matching rows.

> Find a keyword

In System.log, find the row that contains the keyword

grep ' keyword ' System.log

Output line numbers are included in the search for easy viewing

grep ' keyword ' System.log

> Basic Regular expressions supported by default

Find lines that start with 2015-09-24

grep ' ^2015-09-24 ' System.log

> supports extended regular expressions

Regular expressions are used in various fields, and it is more convenient to use it with grep to find files.

In general, grep supports the basic expression, plus the-e option, which supports extended regular expressions.

Find rows that contain keyword1 or keyword2 with line numbers

grep ' Keyword1|keyword2 ' System.log

"Linux" uses grep to find content in a document

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.