grep 筛子 linux三剑客老三 过滤需要的内容,-v 排除内容例子如下::
源文件内容为下,要求打印不含oldboy的内容
[root@shuai shiyan]# cat old.txt
shuai
oldboy
fril
rehat
命令如下:
[root@shuai shiyan]# cat old.txt
shuai
oldboy
fril
rehat
[root@shuai shiyan]# grep -v oldboy old.txt
shuai
fril
rehat
[root@shuai shiyan]#
grep
ett.txt内容
[root@shuai /]# cat ett.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[root@shuai /]#
-B 除了显示匹配的一行以外,并显示该行之前的n行
[root@shuai /]# grep 30 -B 10 ett.txt
20
21
22
23
24
25
26
27
28
29
30
[root@shuai /]#
-A 除了显示匹配的一行以外,并显示该行之后的n行
[root@shuai /]# grep 20 -A 10 ett.txt
20
21
22
23
24
25
26
27
28
29
30
[root@shuai /]#
-C 除了显示匹配的一行以外,并显示该行前后各n行
[root@shuai /]# grep 25 -C 5 ett.txt
20
21
22
23
24
25
26
27
28
29
30
[root@shuai /]#