Linux. grep 命令

Linux. grep 命令

  grep 命令常用参数:

   
-c 仅列出文件中包含模式的行数
-i 忽略模式中字母的大小写
-l 列出带有匹配行的文件名称
-n 在每一行的最前面列出行号
-v 列出所有匹配模式的行
-  
   
   
   

参数: -c

[root@localhost u01]# cat demo6.txt 
h
e
l
l
o

w
o
r
l
d

[root@localhost u01]# 
[root@localhost u01]# grep -c o demo6.txt 
2
[root@localhost u01]# 

参数:-i

[root@localhost u01]# cat demo6.txt 
h
e
l
l
o

w
O # 这个字母o,是大写的.
r
l
d

[root@localhost u01]# grep -c o demo6.txt 
1
[root@localhost u01]# grep -ic o demo6.txt 
2
[root@localhost u01]# 

参数: -l

[root@localhost test]# ll
total 0
[root@localhost test]# echo A > 1.txt
[root@localhost test]# echo a > 2.txt
[root@localhost test]# echo b > 3.txt
[root@localhost test]# 
[root@localhost test]# grep -l a *
2.txt
[root@localhost test]# grep -li a *
1.txt
2.txt
[root@localhost test]# 
[root@localhost test]# 

参数: -n

[root@localhost u01]# cat -n demo6.txt 
     1    h
     2    e
     3    l
     4    l
     5    o
     6    
     7    w
     8    O
     9    r
    10    l
    11    d
    12    
[root@localhost u01]# 
[root@localhost u01]# grep -n r demo6.txt 
9:r
[root@localhost u01]# 
原文地址:https://www.cnblogs.com/Charles-Yuan/p/12202421.html