[root@localhost test]# cat d
aaaaaaaaaaaa
bbbbbbbbbbbb
cccccccccccc
12344566
21312asdasdffsa
asdasd12eqwdas
dsadas12eqwd
asdsad21
abc sda dwdf
sadas sad asd
21ed 12d1 2ed 1d1
111 111 111
12 23 123 412
grep:
-i:查找时忽略大小写
-v:反向查找,输出与查找条件不相符的行
-o 只显示匹配项
-f 对比两个文件的相同行
-c 匹配的行数([root@localhost ky15]# grep -c root passwd 2)
-o:
[root@localhost test]# grep -ion "D" d
5:d
5:d
6:d
6:d
6:d
7:d
7:d
7:d
8:d
8:d
9:d
9:d
9:d
10:d
10:d
10:d
11:d
11:d
11:d
11:d
-c匹配的层数:
[root@localhost test]# grep -ic "D" d
7
$^的使用:一起使用有空行的意思
[root@localhost test]# grep -n "^2" d
5:21312asdasdffsa
11:21ed 12d1 2ed 1d1
[root@localhost test]# grep -n "a$" d
1:aaaaaaaaaaaa
5:21312asdasdffsa
[root@localhost test]# cat a
1
2
3
[root@localhost test]# grep "^$" a
[root@localhost test]# grep -c "^$" a
3
-f:用于比较