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