初识Linux(5)

[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:用于比较

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值