您的位置:首页 > 其它

grep统计某个单词的个数

2007-08-25 10:51 253 查看
j@j:~$ cat hello.c
#include<stdio.h>
//include include
int main(){
printf("hello world/n");
exit(0);
}
j@j:~$ grep -o include hello.c
include
include
include

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

命令grep -c -o include hello.c的结果是2, -c参数只能统计行。如果要统计个数, 可以再来个重定向:

grep -o include hello.c | grep -c include
得到include的个数 3
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: