Grep advanced application 10

Source: Internet
Author: User

1. grep:

-V: displays rows that are not matched by the pattern;

-I: case insensitive;

-O: only the matched strings are displayed;

For example, ifconfig | grep 'inet addr: [^ [: space:] ';

Ifconfig | grep -- color = auto-o 'inet addr: [^ [: space:] * ';

Ifconfig | grep -- color = auto-o 'inet addr: [^ [: space:] * '| cut-d:


-F2 | grep -- color = auto-v '2017. 0.0.1 ';

-A num: after the specified row is displayed, multiple num rows are displayed;

-B num: after the specified row is displayed, the num row is displayed first;

-C num: displays the num rows before and after the specified row;


2. quotation marks

Grep 'pattern'

Grep "PATTERN"

The difference between the two is that if there is a variable, you can use "" and other single double quotation marks;


3. Exercise


A. display the rows starting with "s" of the/proc/meminfo file with no size difference;

Grep -- color = auto-I '^ s. *'/proc/meminfo;


B. display the rows ending with nologin in/etc/passwd;

Grep -- color = auto'nologin $ '/etc/passwd;


C. The/etc/inittab starts with #, followed by one or more white spaces, followed by any non-


Blank line;

Grep -- color = auto' ^ # [[: space:] $]. * [^ [: space:] '/etc/inittab


D. The/etc/inittab displays the rows of a number (that is, a number between two colons;

Grep -- color = auto': [[: digit:]: '/etc/inittab


E. display the lines starting with one or more blank characters in the/boot/grub. conf file;

Grep -- color = auto' ^ [: space:]. * '/boot/grub. conf;


F. display the/etc/inittab file that starts with a number and ends with a number that is the same as the starting number


Line;

Grep -- color = auto' ^ [0-9]. * [0-9] '/etc/inittab or

Grep -- color = auto' \ (^ [0-9] \). * \ 1 '/etc/inittab;


This article is from the blog "Nick Liu's blog", please be sure to keep this source http://zkhylt.blog.51cto.com/3638719/1302204

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.