grep统计某个单词的个数,行数等

文件内容

1
2
3
4
5
6
7
j@j:~$ cat hello.c
#include<stdio.h>
//include include
int main(){
printf("hello world/n");
exit(0);
}

grep命令查看include关键词

1
2
3
4
j@j:~$ grep -o include  hello.c
include
include
include

如上所示, 所有的include都显示出来了, 包括有两个include的行。

命令

1
grep -c -o include  hello.c

的结果是2, -c参数只能统计行。如果要统计个数, 可以再来个重定向:

1
grep -o include hello.c| grep -c include

得到include的个数 3

有问题可以联系博主

转载请注明出处,谢谢