Shell Script--grep command for content lookup

Source: Internet
Author: User

The grep command retrieves the rows in the file that contain keywords (which can be used), and is case-sensitive by default.

  

Use the-c parameter to get the number of rows that contain the keyword

Use the-n parameter to display the line number at the same time that the content is printed

  

Using the-i parameter, when looking, is case insensitive

  

Use the-v parameter to find rows that do not contain keywords

  

To use a regular expression, you can use the-e parameter

The shell is similar to the regular Perl language and is basically generic.

[Email protected]:~/test$ cat Test.txtthis is Linuxthis was Linuxthat is apples[email protected]:~/test$ grep-e ' ^that ' t Est.txt #以that开头的行that was apples[email protected]:~/test$ grep-e ' linux$ ' test.txt #以Linux结尾的行this is Linux[email Protec ted]:~/test$ grep-e '. Inux ' Test.txt # '. ' Represents any one character (not including whitespace) This is linuxthis is Linux[email protected]:~/test$ grep-e ' p* ' test.txt  

There are also some commonly used matching patterns, such as ' ^$ ' for a blank line, ' ^.$ ' represents a line with only one character, and a \ to escape, such as using \. to match a point; [0-9] means matching a number; [a-z]| [A-z] denotes any letter; use | to denote ' or ';

  

  

Shell Script--grep command for content lookup

Related Article

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.